Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * wm8960.c -- WM8960 ALSA SoC Audio driver |
| 3 | * |
| 4 | * Author: Liam Girdwood |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/moduleparam.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/pm.h> |
| 16 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 18 | #include <sound/core.h> |
| 19 | #include <sound/pcm.h> |
| 20 | #include <sound/pcm_params.h> |
| 21 | #include <sound/soc.h> |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 22 | #include <sound/initval.h> |
| 23 | #include <sound/tlv.h> |
Mark Brown | b6877a4 | 2010-03-03 11:43:38 +0000 | [diff] [blame] | 24 | #include <sound/wm8960.h> |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 25 | |
| 26 | #include "wm8960.h" |
| 27 | |
| 28 | #define AUDIO_NAME "wm8960" |
| 29 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 30 | /* R25 - Power 1 */ |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 31 | #define WM8960_VMID_MASK 0x180 |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 32 | #define WM8960_VREF 0x40 |
| 33 | |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 34 | /* R26 - Power 2 */ |
| 35 | #define WM8960_PWR2_LOUT1 0x40 |
| 36 | #define WM8960_PWR2_ROUT1 0x20 |
| 37 | #define WM8960_PWR2_OUT3 0x02 |
| 38 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 39 | /* R28 - Anti-pop 1 */ |
| 40 | #define WM8960_POBCTRL 0x80 |
| 41 | #define WM8960_BUFDCOPEN 0x10 |
| 42 | #define WM8960_BUFIOEN 0x08 |
| 43 | #define WM8960_SOFT_ST 0x04 |
| 44 | #define WM8960_HPSTBY 0x01 |
| 45 | |
| 46 | /* R29 - Anti-pop 2 */ |
| 47 | #define WM8960_DISOP 0x40 |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 48 | #define WM8960_DRES_MASK 0x30 |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * wm8960 register cache |
| 52 | * We can't read the WM8960 register space when we are |
| 53 | * using 2 wire for device control, so we cache them instead. |
| 54 | */ |
| 55 | static const u16 wm8960_reg[WM8960_CACHEREGNUM] = { |
| 56 | 0x0097, 0x0097, 0x0000, 0x0000, |
| 57 | 0x0000, 0x0008, 0x0000, 0x000a, |
| 58 | 0x01c0, 0x0000, 0x00ff, 0x00ff, |
| 59 | 0x0000, 0x0000, 0x0000, 0x0000, |
| 60 | 0x0000, 0x007b, 0x0100, 0x0032, |
| 61 | 0x0000, 0x00c3, 0x00c3, 0x01c0, |
| 62 | 0x0000, 0x0000, 0x0000, 0x0000, |
| 63 | 0x0000, 0x0000, 0x0000, 0x0000, |
| 64 | 0x0100, 0x0100, 0x0050, 0x0050, |
| 65 | 0x0050, 0x0050, 0x0000, 0x0000, |
| 66 | 0x0000, 0x0000, 0x0040, 0x0000, |
| 67 | 0x0000, 0x0050, 0x0050, 0x0000, |
| 68 | 0x0002, 0x0037, 0x004d, 0x0080, |
| 69 | 0x0008, 0x0031, 0x0026, 0x00e9, |
| 70 | }; |
| 71 | |
| 72 | struct wm8960_priv { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 73 | enum snd_soc_control_type control_type; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 74 | int (*set_bias_level)(struct snd_soc_codec *, |
| 75 | enum snd_soc_bias_level level); |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 76 | struct snd_soc_dapm_widget *lout1; |
| 77 | struct snd_soc_dapm_widget *rout1; |
| 78 | struct snd_soc_dapm_widget *out3; |
Mark Brown | afd6d36 | 2010-07-05 13:58:16 +0900 | [diff] [blame] | 79 | bool deemph; |
| 80 | int playback_fs; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 81 | }; |
| 82 | |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 83 | #define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0) |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 84 | |
| 85 | /* enumerated controls */ |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 86 | static const char *wm8960_polarity[] = {"No Inversion", "Left Inverted", |
| 87 | "Right Inverted", "Stereo Inversion"}; |
| 88 | static const char *wm8960_3d_upper_cutoff[] = {"High", "Low"}; |
| 89 | static const char *wm8960_3d_lower_cutoff[] = {"Low", "High"}; |
| 90 | static const char *wm8960_alcfunc[] = {"Off", "Right", "Left", "Stereo"}; |
| 91 | static const char *wm8960_alcmode[] = {"ALC", "Limiter"}; |
| 92 | |
| 93 | static const struct soc_enum wm8960_enum[] = { |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 94 | SOC_ENUM_SINGLE(WM8960_DACCTL1, 5, 4, wm8960_polarity), |
| 95 | SOC_ENUM_SINGLE(WM8960_DACCTL2, 5, 4, wm8960_polarity), |
| 96 | SOC_ENUM_SINGLE(WM8960_3D, 6, 2, wm8960_3d_upper_cutoff), |
| 97 | SOC_ENUM_SINGLE(WM8960_3D, 5, 2, wm8960_3d_lower_cutoff), |
| 98 | SOC_ENUM_SINGLE(WM8960_ALC1, 7, 4, wm8960_alcfunc), |
| 99 | SOC_ENUM_SINGLE(WM8960_ALC3, 8, 2, wm8960_alcmode), |
| 100 | }; |
| 101 | |
Mark Brown | afd6d36 | 2010-07-05 13:58:16 +0900 | [diff] [blame] | 102 | static const int deemph_settings[] = { 0, 32000, 44100, 48000 }; |
| 103 | |
| 104 | static int wm8960_set_deemph(struct snd_soc_codec *codec) |
| 105 | { |
| 106 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
| 107 | int val, i, best; |
| 108 | |
| 109 | /* If we're using deemphasis select the nearest available sample |
| 110 | * rate. |
| 111 | */ |
| 112 | if (wm8960->deemph) { |
| 113 | best = 1; |
| 114 | for (i = 2; i < ARRAY_SIZE(deemph_settings); i++) { |
| 115 | if (abs(deemph_settings[i] - wm8960->playback_fs) < |
| 116 | abs(deemph_settings[best] - wm8960->playback_fs)) |
| 117 | best = i; |
| 118 | } |
| 119 | |
| 120 | val = best << 1; |
| 121 | } else { |
| 122 | val = 0; |
| 123 | } |
| 124 | |
| 125 | dev_dbg(codec->dev, "Set deemphasis %d\n", val); |
| 126 | |
| 127 | return snd_soc_update_bits(codec, WM8960_DACCTL1, |
| 128 | 0x6, val); |
| 129 | } |
| 130 | |
| 131 | static int wm8960_get_deemph(struct snd_kcontrol *kcontrol, |
| 132 | struct snd_ctl_elem_value *ucontrol) |
| 133 | { |
| 134 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 135 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
| 136 | |
Dmitry Artamonow | 3f343f8 | 2010-12-08 23:36:17 +0300 | [diff] [blame] | 137 | ucontrol->value.enumerated.item[0] = wm8960->deemph; |
| 138 | return 0; |
Mark Brown | afd6d36 | 2010-07-05 13:58:16 +0900 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static int wm8960_put_deemph(struct snd_kcontrol *kcontrol, |
| 142 | struct snd_ctl_elem_value *ucontrol) |
| 143 | { |
| 144 | struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); |
| 145 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
| 146 | int deemph = ucontrol->value.enumerated.item[0]; |
| 147 | |
| 148 | if (deemph > 1) |
| 149 | return -EINVAL; |
| 150 | |
| 151 | wm8960->deemph = deemph; |
| 152 | |
| 153 | return wm8960_set_deemph(codec); |
| 154 | } |
| 155 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 156 | static const DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 50, 0); |
| 157 | static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 50, 1); |
| 158 | static const DECLARE_TLV_DB_SCALE(bypass_tlv, -2100, 300, 0); |
| 159 | static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1); |
| 160 | |
| 161 | static const struct snd_kcontrol_new wm8960_snd_controls[] = { |
| 162 | SOC_DOUBLE_R_TLV("Capture Volume", WM8960_LINVOL, WM8960_RINVOL, |
| 163 | 0, 63, 0, adc_tlv), |
| 164 | SOC_DOUBLE_R("Capture Volume ZC Switch", WM8960_LINVOL, WM8960_RINVOL, |
| 165 | 6, 1, 0), |
| 166 | SOC_DOUBLE_R("Capture Switch", WM8960_LINVOL, WM8960_RINVOL, |
| 167 | 7, 1, 0), |
| 168 | |
| 169 | SOC_DOUBLE_R_TLV("Playback Volume", WM8960_LDAC, WM8960_RDAC, |
| 170 | 0, 255, 0, dac_tlv), |
| 171 | |
| 172 | SOC_DOUBLE_R_TLV("Headphone Playback Volume", WM8960_LOUT1, WM8960_ROUT1, |
| 173 | 0, 127, 0, out_tlv), |
| 174 | SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8960_LOUT1, WM8960_ROUT1, |
| 175 | 7, 1, 0), |
| 176 | |
| 177 | SOC_DOUBLE_R_TLV("Speaker Playback Volume", WM8960_LOUT2, WM8960_ROUT2, |
| 178 | 0, 127, 0, out_tlv), |
| 179 | SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8960_LOUT2, WM8960_ROUT2, |
| 180 | 7, 1, 0), |
| 181 | SOC_SINGLE("Speaker DC Volume", WM8960_CLASSD3, 3, 5, 0), |
| 182 | SOC_SINGLE("Speaker AC Volume", WM8960_CLASSD3, 0, 5, 0), |
| 183 | |
| 184 | SOC_SINGLE("PCM Playback -6dB Switch", WM8960_DACCTL1, 7, 1, 0), |
Mark Brown | 4faaa8d | 2010-07-05 13:54:32 +0900 | [diff] [blame] | 185 | SOC_ENUM("ADC Polarity", wm8960_enum[0]), |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 186 | SOC_SINGLE("ADC High Pass Filter Switch", WM8960_DACCTL1, 0, 1, 0), |
| 187 | |
| 188 | SOC_ENUM("DAC Polarity", wm8960_enum[2]), |
Mark Brown | afd6d36 | 2010-07-05 13:58:16 +0900 | [diff] [blame] | 189 | SOC_SINGLE_BOOL_EXT("DAC Deemphasis Switch", 0, |
| 190 | wm8960_get_deemph, wm8960_put_deemph), |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 191 | |
Mark Brown | 4faaa8d | 2010-07-05 13:54:32 +0900 | [diff] [blame] | 192 | SOC_ENUM("3D Filter Upper Cut-Off", wm8960_enum[2]), |
| 193 | SOC_ENUM("3D Filter Lower Cut-Off", wm8960_enum[3]), |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 194 | SOC_SINGLE("3D Volume", WM8960_3D, 1, 15, 0), |
| 195 | SOC_SINGLE("3D Switch", WM8960_3D, 0, 1, 0), |
| 196 | |
Mark Brown | 4faaa8d | 2010-07-05 13:54:32 +0900 | [diff] [blame] | 197 | SOC_ENUM("ALC Function", wm8960_enum[4]), |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 198 | SOC_SINGLE("ALC Max Gain", WM8960_ALC1, 4, 7, 0), |
| 199 | SOC_SINGLE("ALC Target", WM8960_ALC1, 0, 15, 1), |
| 200 | SOC_SINGLE("ALC Min Gain", WM8960_ALC2, 4, 7, 0), |
| 201 | SOC_SINGLE("ALC Hold Time", WM8960_ALC2, 0, 15, 0), |
Mark Brown | 4faaa8d | 2010-07-05 13:54:32 +0900 | [diff] [blame] | 202 | SOC_ENUM("ALC Mode", wm8960_enum[5]), |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 203 | SOC_SINGLE("ALC Decay", WM8960_ALC3, 4, 15, 0), |
| 204 | SOC_SINGLE("ALC Attack", WM8960_ALC3, 0, 15, 0), |
| 205 | |
| 206 | SOC_SINGLE("Noise Gate Threshold", WM8960_NOISEG, 3, 31, 0), |
| 207 | SOC_SINGLE("Noise Gate Switch", WM8960_NOISEG, 0, 1, 0), |
| 208 | |
| 209 | SOC_DOUBLE_R("ADC PCM Capture Volume", WM8960_LINPATH, WM8960_RINPATH, |
| 210 | 0, 127, 0), |
| 211 | |
| 212 | SOC_SINGLE_TLV("Left Output Mixer Boost Bypass Volume", |
| 213 | WM8960_BYPASS1, 4, 7, 1, bypass_tlv), |
| 214 | SOC_SINGLE_TLV("Left Output Mixer LINPUT3 Volume", |
| 215 | WM8960_LOUTMIX, 4, 7, 1, bypass_tlv), |
| 216 | SOC_SINGLE_TLV("Right Output Mixer Boost Bypass Volume", |
| 217 | WM8960_BYPASS2, 4, 7, 1, bypass_tlv), |
| 218 | SOC_SINGLE_TLV("Right Output Mixer RINPUT3 Volume", |
| 219 | WM8960_ROUTMIX, 4, 7, 1, bypass_tlv), |
| 220 | }; |
| 221 | |
| 222 | static const struct snd_kcontrol_new wm8960_lin_boost[] = { |
| 223 | SOC_DAPM_SINGLE("LINPUT2 Switch", WM8960_LINPATH, 6, 1, 0), |
| 224 | SOC_DAPM_SINGLE("LINPUT3 Switch", WM8960_LINPATH, 7, 1, 0), |
| 225 | SOC_DAPM_SINGLE("LINPUT1 Switch", WM8960_LINPATH, 8, 1, 0), |
| 226 | }; |
| 227 | |
| 228 | static const struct snd_kcontrol_new wm8960_lin[] = { |
| 229 | SOC_DAPM_SINGLE("Boost Switch", WM8960_LINPATH, 3, 1, 0), |
| 230 | }; |
| 231 | |
| 232 | static const struct snd_kcontrol_new wm8960_rin_boost[] = { |
| 233 | SOC_DAPM_SINGLE("RINPUT2 Switch", WM8960_RINPATH, 6, 1, 0), |
| 234 | SOC_DAPM_SINGLE("RINPUT3 Switch", WM8960_RINPATH, 7, 1, 0), |
| 235 | SOC_DAPM_SINGLE("RINPUT1 Switch", WM8960_RINPATH, 8, 1, 0), |
| 236 | }; |
| 237 | |
| 238 | static const struct snd_kcontrol_new wm8960_rin[] = { |
| 239 | SOC_DAPM_SINGLE("Boost Switch", WM8960_RINPATH, 3, 1, 0), |
| 240 | }; |
| 241 | |
| 242 | static const struct snd_kcontrol_new wm8960_loutput_mixer[] = { |
| 243 | SOC_DAPM_SINGLE("PCM Playback Switch", WM8960_LOUTMIX, 8, 1, 0), |
| 244 | SOC_DAPM_SINGLE("LINPUT3 Switch", WM8960_LOUTMIX, 7, 1, 0), |
| 245 | SOC_DAPM_SINGLE("Boost Bypass Switch", WM8960_BYPASS1, 7, 1, 0), |
| 246 | }; |
| 247 | |
| 248 | static const struct snd_kcontrol_new wm8960_routput_mixer[] = { |
| 249 | SOC_DAPM_SINGLE("PCM Playback Switch", WM8960_ROUTMIX, 8, 1, 0), |
| 250 | SOC_DAPM_SINGLE("RINPUT3 Switch", WM8960_ROUTMIX, 7, 1, 0), |
| 251 | SOC_DAPM_SINGLE("Boost Bypass Switch", WM8960_BYPASS2, 7, 1, 0), |
| 252 | }; |
| 253 | |
| 254 | static const struct snd_kcontrol_new wm8960_mono_out[] = { |
| 255 | SOC_DAPM_SINGLE("Left Switch", WM8960_MONOMIX1, 7, 1, 0), |
| 256 | SOC_DAPM_SINGLE("Right Switch", WM8960_MONOMIX2, 7, 1, 0), |
| 257 | }; |
| 258 | |
| 259 | static const struct snd_soc_dapm_widget wm8960_dapm_widgets[] = { |
| 260 | SND_SOC_DAPM_INPUT("LINPUT1"), |
| 261 | SND_SOC_DAPM_INPUT("RINPUT1"), |
| 262 | SND_SOC_DAPM_INPUT("LINPUT2"), |
| 263 | SND_SOC_DAPM_INPUT("RINPUT2"), |
| 264 | SND_SOC_DAPM_INPUT("LINPUT3"), |
| 265 | SND_SOC_DAPM_INPUT("RINPUT3"), |
| 266 | |
Mark Brown | 187774c | 2011-10-27 09:46:17 +0200 | [diff] [blame] | 267 | SND_SOC_DAPM_SUPPLY("MICB", WM8960_POWER1, 1, 0, NULL, 0), |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 268 | |
| 269 | SND_SOC_DAPM_MIXER("Left Boost Mixer", WM8960_POWER1, 5, 0, |
| 270 | wm8960_lin_boost, ARRAY_SIZE(wm8960_lin_boost)), |
| 271 | SND_SOC_DAPM_MIXER("Right Boost Mixer", WM8960_POWER1, 4, 0, |
| 272 | wm8960_rin_boost, ARRAY_SIZE(wm8960_rin_boost)), |
| 273 | |
| 274 | SND_SOC_DAPM_MIXER("Left Input Mixer", WM8960_POWER3, 5, 0, |
| 275 | wm8960_lin, ARRAY_SIZE(wm8960_lin)), |
| 276 | SND_SOC_DAPM_MIXER("Right Input Mixer", WM8960_POWER3, 4, 0, |
| 277 | wm8960_rin, ARRAY_SIZE(wm8960_rin)), |
| 278 | |
| 279 | SND_SOC_DAPM_ADC("Left ADC", "Capture", WM8960_POWER2, 3, 0), |
| 280 | SND_SOC_DAPM_ADC("Right ADC", "Capture", WM8960_POWER2, 2, 0), |
| 281 | |
| 282 | SND_SOC_DAPM_DAC("Left DAC", "Playback", WM8960_POWER2, 8, 0), |
| 283 | SND_SOC_DAPM_DAC("Right DAC", "Playback", WM8960_POWER2, 7, 0), |
| 284 | |
| 285 | SND_SOC_DAPM_MIXER("Left Output Mixer", WM8960_POWER3, 3, 0, |
| 286 | &wm8960_loutput_mixer[0], |
| 287 | ARRAY_SIZE(wm8960_loutput_mixer)), |
| 288 | SND_SOC_DAPM_MIXER("Right Output Mixer", WM8960_POWER3, 2, 0, |
| 289 | &wm8960_routput_mixer[0], |
| 290 | ARRAY_SIZE(wm8960_routput_mixer)), |
| 291 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 292 | SND_SOC_DAPM_PGA("LOUT1 PGA", WM8960_POWER2, 6, 0, NULL, 0), |
| 293 | SND_SOC_DAPM_PGA("ROUT1 PGA", WM8960_POWER2, 5, 0, NULL, 0), |
| 294 | |
| 295 | SND_SOC_DAPM_PGA("Left Speaker PGA", WM8960_POWER2, 4, 0, NULL, 0), |
| 296 | SND_SOC_DAPM_PGA("Right Speaker PGA", WM8960_POWER2, 3, 0, NULL, 0), |
| 297 | |
| 298 | SND_SOC_DAPM_PGA("Right Speaker Output", WM8960_CLASSD1, 7, 0, NULL, 0), |
| 299 | SND_SOC_DAPM_PGA("Left Speaker Output", WM8960_CLASSD1, 6, 0, NULL, 0), |
| 300 | |
| 301 | SND_SOC_DAPM_OUTPUT("SPK_LP"), |
| 302 | SND_SOC_DAPM_OUTPUT("SPK_LN"), |
| 303 | SND_SOC_DAPM_OUTPUT("HP_L"), |
| 304 | SND_SOC_DAPM_OUTPUT("HP_R"), |
| 305 | SND_SOC_DAPM_OUTPUT("SPK_RP"), |
| 306 | SND_SOC_DAPM_OUTPUT("SPK_RN"), |
| 307 | SND_SOC_DAPM_OUTPUT("OUT3"), |
| 308 | }; |
| 309 | |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 310 | static const struct snd_soc_dapm_widget wm8960_dapm_widgets_out3[] = { |
| 311 | SND_SOC_DAPM_MIXER("Mono Output Mixer", WM8960_POWER2, 1, 0, |
| 312 | &wm8960_mono_out[0], |
| 313 | ARRAY_SIZE(wm8960_mono_out)), |
| 314 | }; |
| 315 | |
| 316 | /* Represent OUT3 as a PGA so that it gets turned on with LOUT1/ROUT1 */ |
| 317 | static const struct snd_soc_dapm_widget wm8960_dapm_widgets_capless[] = { |
| 318 | SND_SOC_DAPM_PGA("OUT3 VMID", WM8960_POWER2, 1, 0, NULL, 0), |
| 319 | }; |
| 320 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 321 | static const struct snd_soc_dapm_route audio_paths[] = { |
| 322 | { "Left Boost Mixer", "LINPUT1 Switch", "LINPUT1" }, |
| 323 | { "Left Boost Mixer", "LINPUT2 Switch", "LINPUT2" }, |
| 324 | { "Left Boost Mixer", "LINPUT3 Switch", "LINPUT3" }, |
| 325 | |
| 326 | { "Left Input Mixer", "Boost Switch", "Left Boost Mixer", }, |
| 327 | { "Left Input Mixer", NULL, "LINPUT1", }, /* Really Boost Switch */ |
| 328 | { "Left Input Mixer", NULL, "LINPUT2" }, |
| 329 | { "Left Input Mixer", NULL, "LINPUT3" }, |
| 330 | |
| 331 | { "Right Boost Mixer", "RINPUT1 Switch", "RINPUT1" }, |
| 332 | { "Right Boost Mixer", "RINPUT2 Switch", "RINPUT2" }, |
| 333 | { "Right Boost Mixer", "RINPUT3 Switch", "RINPUT3" }, |
| 334 | |
| 335 | { "Right Input Mixer", "Boost Switch", "Right Boost Mixer", }, |
| 336 | { "Right Input Mixer", NULL, "RINPUT1", }, /* Really Boost Switch */ |
| 337 | { "Right Input Mixer", NULL, "RINPUT2" }, |
| 338 | { "Right Input Mixer", NULL, "LINPUT3" }, |
| 339 | |
| 340 | { "Left ADC", NULL, "Left Input Mixer" }, |
| 341 | { "Right ADC", NULL, "Right Input Mixer" }, |
| 342 | |
| 343 | { "Left Output Mixer", "LINPUT3 Switch", "LINPUT3" }, |
| 344 | { "Left Output Mixer", "Boost Bypass Switch", "Left Boost Mixer"} , |
| 345 | { "Left Output Mixer", "PCM Playback Switch", "Left DAC" }, |
| 346 | |
| 347 | { "Right Output Mixer", "RINPUT3 Switch", "RINPUT3" }, |
| 348 | { "Right Output Mixer", "Boost Bypass Switch", "Right Boost Mixer" } , |
| 349 | { "Right Output Mixer", "PCM Playback Switch", "Right DAC" }, |
| 350 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 351 | { "LOUT1 PGA", NULL, "Left Output Mixer" }, |
| 352 | { "ROUT1 PGA", NULL, "Right Output Mixer" }, |
| 353 | |
| 354 | { "HP_L", NULL, "LOUT1 PGA" }, |
| 355 | { "HP_R", NULL, "ROUT1 PGA" }, |
| 356 | |
| 357 | { "Left Speaker PGA", NULL, "Left Output Mixer" }, |
| 358 | { "Right Speaker PGA", NULL, "Right Output Mixer" }, |
| 359 | |
| 360 | { "Left Speaker Output", NULL, "Left Speaker PGA" }, |
| 361 | { "Right Speaker Output", NULL, "Right Speaker PGA" }, |
| 362 | |
| 363 | { "SPK_LN", NULL, "Left Speaker Output" }, |
| 364 | { "SPK_LP", NULL, "Left Speaker Output" }, |
| 365 | { "SPK_RN", NULL, "Right Speaker Output" }, |
| 366 | { "SPK_RP", NULL, "Right Speaker Output" }, |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 367 | }; |
| 368 | |
| 369 | static const struct snd_soc_dapm_route audio_paths_out3[] = { |
| 370 | { "Mono Output Mixer", "Left Switch", "Left Output Mixer" }, |
| 371 | { "Mono Output Mixer", "Right Switch", "Right Output Mixer" }, |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 372 | |
| 373 | { "OUT3", NULL, "Mono Output Mixer", } |
| 374 | }; |
| 375 | |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 376 | static const struct snd_soc_dapm_route audio_paths_capless[] = { |
| 377 | { "HP_L", NULL, "OUT3 VMID" }, |
| 378 | { "HP_R", NULL, "OUT3 VMID" }, |
| 379 | |
| 380 | { "OUT3 VMID", NULL, "Left Output Mixer" }, |
| 381 | { "OUT3 VMID", NULL, "Right Output Mixer" }, |
| 382 | }; |
| 383 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 384 | static int wm8960_add_widgets(struct snd_soc_codec *codec) |
| 385 | { |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 386 | struct wm8960_data *pdata = codec->dev->platform_data; |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 387 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 388 | struct snd_soc_dapm_context *dapm = &codec->dapm; |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 389 | struct snd_soc_dapm_widget *w; |
| 390 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 391 | snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets, |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 392 | ARRAY_SIZE(wm8960_dapm_widgets)); |
| 393 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 394 | snd_soc_dapm_add_routes(dapm, audio_paths, ARRAY_SIZE(audio_paths)); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 395 | |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 396 | /* In capless mode OUT3 is used to provide VMID for the |
| 397 | * headphone outputs, otherwise it is used as a mono mixer. |
| 398 | */ |
| 399 | if (pdata && pdata->capless) { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 400 | snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets_capless, |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 401 | ARRAY_SIZE(wm8960_dapm_widgets_capless)); |
| 402 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 403 | snd_soc_dapm_add_routes(dapm, audio_paths_capless, |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 404 | ARRAY_SIZE(audio_paths_capless)); |
| 405 | } else { |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 406 | snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets_out3, |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 407 | ARRAY_SIZE(wm8960_dapm_widgets_out3)); |
| 408 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 409 | snd_soc_dapm_add_routes(dapm, audio_paths_out3, |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 410 | ARRAY_SIZE(audio_paths_out3)); |
| 411 | } |
| 412 | |
| 413 | /* We need to power up the headphone output stage out of |
| 414 | * sequence for capless mode. To save scanning the widget |
| 415 | * list each time to find the desired power state do so now |
| 416 | * and save the result. |
| 417 | */ |
Jarkko Nikula | 97c866d | 2010-12-14 12:18:31 +0200 | [diff] [blame] | 418 | list_for_each_entry(w, &codec->card->widgets, list) { |
| 419 | if (w->dapm != &codec->dapm) |
| 420 | continue; |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 421 | if (strcmp(w->name, "LOUT1 PGA") == 0) |
| 422 | wm8960->lout1 = w; |
| 423 | if (strcmp(w->name, "ROUT1 PGA") == 0) |
| 424 | wm8960->rout1 = w; |
| 425 | if (strcmp(w->name, "OUT3 VMID") == 0) |
| 426 | wm8960->out3 = w; |
| 427 | } |
| 428 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 429 | return 0; |
| 430 | } |
| 431 | |
| 432 | static int wm8960_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 433 | unsigned int fmt) |
| 434 | { |
| 435 | struct snd_soc_codec *codec = codec_dai->codec; |
| 436 | u16 iface = 0; |
| 437 | |
| 438 | /* set master/slave audio interface */ |
| 439 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 440 | case SND_SOC_DAIFMT_CBM_CFM: |
| 441 | iface |= 0x0040; |
| 442 | break; |
| 443 | case SND_SOC_DAIFMT_CBS_CFS: |
| 444 | break; |
| 445 | default: |
| 446 | return -EINVAL; |
| 447 | } |
| 448 | |
| 449 | /* interface format */ |
| 450 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 451 | case SND_SOC_DAIFMT_I2S: |
| 452 | iface |= 0x0002; |
| 453 | break; |
| 454 | case SND_SOC_DAIFMT_RIGHT_J: |
| 455 | break; |
| 456 | case SND_SOC_DAIFMT_LEFT_J: |
| 457 | iface |= 0x0001; |
| 458 | break; |
| 459 | case SND_SOC_DAIFMT_DSP_A: |
| 460 | iface |= 0x0003; |
| 461 | break; |
| 462 | case SND_SOC_DAIFMT_DSP_B: |
| 463 | iface |= 0x0013; |
| 464 | break; |
| 465 | default: |
| 466 | return -EINVAL; |
| 467 | } |
| 468 | |
| 469 | /* clock inversion */ |
| 470 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 471 | case SND_SOC_DAIFMT_NB_NF: |
| 472 | break; |
| 473 | case SND_SOC_DAIFMT_IB_IF: |
| 474 | iface |= 0x0090; |
| 475 | break; |
| 476 | case SND_SOC_DAIFMT_IB_NF: |
| 477 | iface |= 0x0080; |
| 478 | break; |
| 479 | case SND_SOC_DAIFMT_NB_IF: |
| 480 | iface |= 0x0010; |
| 481 | break; |
| 482 | default: |
| 483 | return -EINVAL; |
| 484 | } |
| 485 | |
| 486 | /* set iface */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 487 | snd_soc_write(codec, WM8960_IFACE1, iface); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 488 | return 0; |
| 489 | } |
| 490 | |
Mark Brown | db059c0 | 2010-07-05 23:54:51 +0900 | [diff] [blame] | 491 | static struct { |
| 492 | int rate; |
| 493 | unsigned int val; |
| 494 | } alc_rates[] = { |
| 495 | { 48000, 0 }, |
| 496 | { 44100, 0 }, |
| 497 | { 32000, 1 }, |
| 498 | { 22050, 2 }, |
| 499 | { 24000, 2 }, |
| 500 | { 16000, 3 }, |
| 501 | { 11250, 4 }, |
| 502 | { 12000, 4 }, |
| 503 | { 8000, 5 }, |
| 504 | }; |
| 505 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 506 | static int wm8960_hw_params(struct snd_pcm_substream *substream, |
| 507 | struct snd_pcm_hw_params *params, |
| 508 | struct snd_soc_dai *dai) |
| 509 | { |
| 510 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 511 | struct snd_soc_codec *codec = rtd->codec; |
Mark Brown | afd6d36 | 2010-07-05 13:58:16 +0900 | [diff] [blame] | 512 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 513 | u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3; |
Mark Brown | db059c0 | 2010-07-05 23:54:51 +0900 | [diff] [blame] | 514 | int i; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 515 | |
| 516 | /* bit size */ |
| 517 | switch (params_format(params)) { |
| 518 | case SNDRV_PCM_FORMAT_S16_LE: |
| 519 | break; |
| 520 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 521 | iface |= 0x0004; |
| 522 | break; |
| 523 | case SNDRV_PCM_FORMAT_S24_LE: |
| 524 | iface |= 0x0008; |
| 525 | break; |
| 526 | } |
| 527 | |
Mark Brown | afd6d36 | 2010-07-05 13:58:16 +0900 | [diff] [blame] | 528 | /* Update filters for the new rate */ |
| 529 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 530 | wm8960->playback_fs = params_rate(params); |
| 531 | wm8960_set_deemph(codec); |
Mark Brown | db059c0 | 2010-07-05 23:54:51 +0900 | [diff] [blame] | 532 | } else { |
| 533 | for (i = 0; i < ARRAY_SIZE(alc_rates); i++) |
| 534 | if (alc_rates[i].rate == params_rate(params)) |
| 535 | snd_soc_update_bits(codec, |
| 536 | WM8960_ADDCTL3, 0x7, |
| 537 | alc_rates[i].val); |
Mark Brown | afd6d36 | 2010-07-05 13:58:16 +0900 | [diff] [blame] | 538 | } |
| 539 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 540 | /* set iface */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 541 | snd_soc_write(codec, WM8960_IFACE1, iface); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static int wm8960_mute(struct snd_soc_dai *dai, int mute) |
| 546 | { |
| 547 | struct snd_soc_codec *codec = dai->codec; |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 548 | u16 mute_reg = snd_soc_read(codec, WM8960_DACCTL1) & 0xfff7; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 549 | |
| 550 | if (mute) |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 551 | snd_soc_write(codec, WM8960_DACCTL1, mute_reg | 0x8); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 552 | else |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 553 | snd_soc_write(codec, WM8960_DACCTL1, mute_reg); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 554 | return 0; |
| 555 | } |
| 556 | |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 557 | static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec, |
| 558 | enum snd_soc_bias_level level) |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 559 | { |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 560 | u16 reg; |
| 561 | |
| 562 | switch (level) { |
| 563 | case SND_SOC_BIAS_ON: |
| 564 | break; |
| 565 | |
| 566 | case SND_SOC_BIAS_PREPARE: |
| 567 | /* Set VMID to 2x50k */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 568 | reg = snd_soc_read(codec, WM8960_POWER1); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 569 | reg &= ~0x180; |
| 570 | reg |= 0x80; |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 571 | snd_soc_write(codec, WM8960_POWER1, reg); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 572 | break; |
| 573 | |
| 574 | case SND_SOC_BIAS_STANDBY: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 575 | if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) { |
Axel Lin | bc45df2 | 2011-10-07 21:50:23 +0800 | [diff] [blame] | 576 | snd_soc_cache_sync(codec); |
| 577 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 578 | /* Enable anti-pop features */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 579 | snd_soc_write(codec, WM8960_APOP1, |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 580 | WM8960_POBCTRL | WM8960_SOFT_ST | |
| 581 | WM8960_BUFDCOPEN | WM8960_BUFIOEN); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 582 | |
| 583 | /* Enable & ramp VMID at 2x50k */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 584 | reg = snd_soc_read(codec, WM8960_POWER1); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 585 | reg |= 0x80; |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 586 | snd_soc_write(codec, WM8960_POWER1, reg); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 587 | msleep(100); |
| 588 | |
| 589 | /* Enable VREF */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 590 | snd_soc_write(codec, WM8960_POWER1, reg | WM8960_VREF); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 591 | |
| 592 | /* Disable anti-pop features */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 593 | snd_soc_write(codec, WM8960_APOP1, WM8960_BUFIOEN); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /* Set VMID to 2x250k */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 597 | reg = snd_soc_read(codec, WM8960_POWER1); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 598 | reg &= ~0x180; |
| 599 | reg |= 0x100; |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 600 | snd_soc_write(codec, WM8960_POWER1, reg); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 601 | break; |
| 602 | |
| 603 | case SND_SOC_BIAS_OFF: |
| 604 | /* Enable anti-pop features */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 605 | snd_soc_write(codec, WM8960_APOP1, |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 606 | WM8960_POBCTRL | WM8960_SOFT_ST | |
| 607 | WM8960_BUFDCOPEN | WM8960_BUFIOEN); |
| 608 | |
| 609 | /* Disable VMID and VREF, let them discharge */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 610 | snd_soc_write(codec, WM8960_POWER1, 0); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 611 | msleep(600); |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 612 | break; |
| 613 | } |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 614 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 615 | codec->dapm.bias_level = level; |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 616 | |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec, |
| 621 | enum snd_soc_bias_level level) |
| 622 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 623 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 624 | int reg; |
| 625 | |
| 626 | switch (level) { |
| 627 | case SND_SOC_BIAS_ON: |
| 628 | break; |
| 629 | |
| 630 | case SND_SOC_BIAS_PREPARE: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 631 | switch (codec->dapm.bias_level) { |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 632 | case SND_SOC_BIAS_STANDBY: |
| 633 | /* Enable anti pop mode */ |
| 634 | snd_soc_update_bits(codec, WM8960_APOP1, |
| 635 | WM8960_POBCTRL | WM8960_SOFT_ST | |
| 636 | WM8960_BUFDCOPEN, |
| 637 | WM8960_POBCTRL | WM8960_SOFT_ST | |
| 638 | WM8960_BUFDCOPEN); |
| 639 | |
| 640 | /* Enable LOUT1, ROUT1 and OUT3 if they're enabled */ |
| 641 | reg = 0; |
| 642 | if (wm8960->lout1 && wm8960->lout1->power) |
| 643 | reg |= WM8960_PWR2_LOUT1; |
| 644 | if (wm8960->rout1 && wm8960->rout1->power) |
| 645 | reg |= WM8960_PWR2_ROUT1; |
| 646 | if (wm8960->out3 && wm8960->out3->power) |
| 647 | reg |= WM8960_PWR2_OUT3; |
| 648 | snd_soc_update_bits(codec, WM8960_POWER2, |
| 649 | WM8960_PWR2_LOUT1 | |
| 650 | WM8960_PWR2_ROUT1 | |
| 651 | WM8960_PWR2_OUT3, reg); |
| 652 | |
| 653 | /* Enable VMID at 2*50k */ |
| 654 | snd_soc_update_bits(codec, WM8960_POWER1, |
| 655 | WM8960_VMID_MASK, 0x80); |
| 656 | |
| 657 | /* Ramp */ |
| 658 | msleep(100); |
| 659 | |
| 660 | /* Enable VREF */ |
| 661 | snd_soc_update_bits(codec, WM8960_POWER1, |
| 662 | WM8960_VREF, WM8960_VREF); |
| 663 | |
| 664 | msleep(100); |
| 665 | break; |
| 666 | |
| 667 | case SND_SOC_BIAS_ON: |
| 668 | /* Enable anti-pop mode */ |
| 669 | snd_soc_update_bits(codec, WM8960_APOP1, |
| 670 | WM8960_POBCTRL | WM8960_SOFT_ST | |
| 671 | WM8960_BUFDCOPEN, |
| 672 | WM8960_POBCTRL | WM8960_SOFT_ST | |
| 673 | WM8960_BUFDCOPEN); |
| 674 | |
| 675 | /* Disable VMID and VREF */ |
| 676 | snd_soc_update_bits(codec, WM8960_POWER1, |
| 677 | WM8960_VREF | WM8960_VMID_MASK, 0); |
| 678 | break; |
| 679 | |
Axel Lin | bc45df2 | 2011-10-07 21:50:23 +0800 | [diff] [blame] | 680 | case SND_SOC_BIAS_OFF: |
| 681 | snd_soc_cache_sync(codec); |
| 682 | break; |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 683 | default: |
| 684 | break; |
| 685 | } |
| 686 | break; |
| 687 | |
| 688 | case SND_SOC_BIAS_STANDBY: |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 689 | switch (codec->dapm.bias_level) { |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 690 | case SND_SOC_BIAS_PREPARE: |
| 691 | /* Disable HP discharge */ |
| 692 | snd_soc_update_bits(codec, WM8960_APOP2, |
| 693 | WM8960_DISOP | WM8960_DRES_MASK, |
| 694 | 0); |
| 695 | |
| 696 | /* Disable anti-pop features */ |
| 697 | snd_soc_update_bits(codec, WM8960_APOP1, |
| 698 | WM8960_POBCTRL | WM8960_SOFT_ST | |
| 699 | WM8960_BUFDCOPEN, |
| 700 | WM8960_POBCTRL | WM8960_SOFT_ST | |
| 701 | WM8960_BUFDCOPEN); |
| 702 | break; |
| 703 | |
| 704 | default: |
| 705 | break; |
| 706 | } |
| 707 | break; |
| 708 | |
| 709 | case SND_SOC_BIAS_OFF: |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 710 | break; |
| 711 | } |
| 712 | |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 713 | codec->dapm.bias_level = level; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 714 | |
| 715 | return 0; |
| 716 | } |
| 717 | |
| 718 | /* PLL divisors */ |
| 719 | struct _pll_div { |
| 720 | u32 pre_div:1; |
| 721 | u32 n:4; |
| 722 | u32 k:24; |
| 723 | }; |
| 724 | |
| 725 | /* The size in bits of the pll divide multiplied by 10 |
| 726 | * to allow rounding later */ |
| 727 | #define FIXED_PLL_SIZE ((1 << 24) * 10) |
| 728 | |
| 729 | static int pll_factors(unsigned int source, unsigned int target, |
| 730 | struct _pll_div *pll_div) |
| 731 | { |
| 732 | unsigned long long Kpart; |
| 733 | unsigned int K, Ndiv, Nmod; |
| 734 | |
| 735 | pr_debug("WM8960 PLL: setting %dHz->%dHz\n", source, target); |
| 736 | |
| 737 | /* Scale up target to PLL operating frequency */ |
| 738 | target *= 4; |
| 739 | |
| 740 | Ndiv = target / source; |
| 741 | if (Ndiv < 6) { |
| 742 | source >>= 1; |
| 743 | pll_div->pre_div = 1; |
| 744 | Ndiv = target / source; |
| 745 | } else |
| 746 | pll_div->pre_div = 0; |
| 747 | |
| 748 | if ((Ndiv < 6) || (Ndiv > 12)) { |
| 749 | pr_err("WM8960 PLL: Unsupported N=%d\n", Ndiv); |
| 750 | return -EINVAL; |
| 751 | } |
| 752 | |
| 753 | pll_div->n = Ndiv; |
| 754 | Nmod = target % source; |
| 755 | Kpart = FIXED_PLL_SIZE * (long long)Nmod; |
| 756 | |
| 757 | do_div(Kpart, source); |
| 758 | |
| 759 | K = Kpart & 0xFFFFFFFF; |
| 760 | |
| 761 | /* Check if we need to round */ |
| 762 | if ((K % 10) >= 5) |
| 763 | K += 5; |
| 764 | |
| 765 | /* Move down to proper range now rounding is done */ |
| 766 | K /= 10; |
| 767 | |
| 768 | pll_div->k = K; |
| 769 | |
| 770 | pr_debug("WM8960 PLL: N=%x K=%x pre_div=%d\n", |
| 771 | pll_div->n, pll_div->k, pll_div->pre_div); |
| 772 | |
| 773 | return 0; |
| 774 | } |
| 775 | |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 776 | static int wm8960_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, |
| 777 | int source, unsigned int freq_in, unsigned int freq_out) |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 778 | { |
| 779 | struct snd_soc_codec *codec = codec_dai->codec; |
| 780 | u16 reg; |
| 781 | static struct _pll_div pll_div; |
| 782 | int ret; |
| 783 | |
| 784 | if (freq_in && freq_out) { |
| 785 | ret = pll_factors(freq_in, freq_out, &pll_div); |
| 786 | if (ret != 0) |
| 787 | return ret; |
| 788 | } |
| 789 | |
| 790 | /* Disable the PLL: even if we are changing the frequency the |
| 791 | * PLL needs to be disabled while we do so. */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 792 | snd_soc_write(codec, WM8960_CLOCK1, |
| 793 | snd_soc_read(codec, WM8960_CLOCK1) & ~1); |
| 794 | snd_soc_write(codec, WM8960_POWER2, |
| 795 | snd_soc_read(codec, WM8960_POWER2) & ~1); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 796 | |
| 797 | if (!freq_in || !freq_out) |
| 798 | return 0; |
| 799 | |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 800 | reg = snd_soc_read(codec, WM8960_PLL1) & ~0x3f; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 801 | reg |= pll_div.pre_div << 4; |
| 802 | reg |= pll_div.n; |
| 803 | |
| 804 | if (pll_div.k) { |
| 805 | reg |= 0x20; |
| 806 | |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 807 | snd_soc_write(codec, WM8960_PLL2, (pll_div.k >> 18) & 0x3f); |
| 808 | snd_soc_write(codec, WM8960_PLL3, (pll_div.k >> 9) & 0x1ff); |
| 809 | snd_soc_write(codec, WM8960_PLL4, pll_div.k & 0x1ff); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 810 | } |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 811 | snd_soc_write(codec, WM8960_PLL1, reg); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 812 | |
| 813 | /* Turn it on */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 814 | snd_soc_write(codec, WM8960_POWER2, |
| 815 | snd_soc_read(codec, WM8960_POWER2) | 1); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 816 | msleep(250); |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 817 | snd_soc_write(codec, WM8960_CLOCK1, |
| 818 | snd_soc_read(codec, WM8960_CLOCK1) | 1); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 819 | |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai, |
| 824 | int div_id, int div) |
| 825 | { |
| 826 | struct snd_soc_codec *codec = codec_dai->codec; |
| 827 | u16 reg; |
| 828 | |
| 829 | switch (div_id) { |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 830 | case WM8960_SYSCLKDIV: |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 831 | reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1f9; |
| 832 | snd_soc_write(codec, WM8960_CLOCK1, reg | div); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 833 | break; |
| 834 | case WM8960_DACDIV: |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 835 | reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1c7; |
| 836 | snd_soc_write(codec, WM8960_CLOCK1, reg | div); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 837 | break; |
| 838 | case WM8960_OPCLKDIV: |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 839 | reg = snd_soc_read(codec, WM8960_PLL1) & 0x03f; |
| 840 | snd_soc_write(codec, WM8960_PLL1, reg | div); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 841 | break; |
| 842 | case WM8960_DCLKDIV: |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 843 | reg = snd_soc_read(codec, WM8960_CLOCK2) & 0x03f; |
| 844 | snd_soc_write(codec, WM8960_CLOCK2, reg | div); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 845 | break; |
| 846 | case WM8960_TOCLKSEL: |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 847 | reg = snd_soc_read(codec, WM8960_ADDCTL1) & 0x1fd; |
| 848 | snd_soc_write(codec, WM8960_ADDCTL1, reg | div); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 849 | break; |
| 850 | default: |
| 851 | return -EINVAL; |
| 852 | } |
| 853 | |
| 854 | return 0; |
| 855 | } |
| 856 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 857 | static int wm8960_set_bias_level(struct snd_soc_codec *codec, |
| 858 | enum snd_soc_bias_level level) |
| 859 | { |
| 860 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
| 861 | |
| 862 | return wm8960->set_bias_level(codec, level); |
| 863 | } |
| 864 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 865 | #define WM8960_RATES SNDRV_PCM_RATE_8000_48000 |
| 866 | |
| 867 | #define WM8960_FORMATS \ |
| 868 | (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ |
| 869 | SNDRV_PCM_FMTBIT_S24_LE) |
| 870 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 871 | static const struct snd_soc_dai_ops wm8960_dai_ops = { |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 872 | .hw_params = wm8960_hw_params, |
| 873 | .digital_mute = wm8960_mute, |
| 874 | .set_fmt = wm8960_set_dai_fmt, |
| 875 | .set_clkdiv = wm8960_set_dai_clkdiv, |
| 876 | .set_pll = wm8960_set_dai_pll, |
| 877 | }; |
| 878 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 879 | static struct snd_soc_dai_driver wm8960_dai = { |
| 880 | .name = "wm8960-hifi", |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 881 | .playback = { |
| 882 | .stream_name = "Playback", |
| 883 | .channels_min = 1, |
| 884 | .channels_max = 2, |
| 885 | .rates = WM8960_RATES, |
| 886 | .formats = WM8960_FORMATS,}, |
| 887 | .capture = { |
| 888 | .stream_name = "Capture", |
| 889 | .channels_min = 1, |
| 890 | .channels_max = 2, |
| 891 | .rates = WM8960_RATES, |
| 892 | .formats = WM8960_FORMATS,}, |
| 893 | .ops = &wm8960_dai_ops, |
| 894 | .symmetric_rates = 1, |
| 895 | }; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 896 | |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 897 | static int wm8960_suspend(struct snd_soc_codec *codec) |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 898 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 899 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 900 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 901 | wm8960->set_bias_level(codec, SND_SOC_BIAS_OFF); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 902 | return 0; |
| 903 | } |
| 904 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 905 | static int wm8960_resume(struct snd_soc_codec *codec) |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 906 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 907 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 908 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 909 | wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 910 | return 0; |
| 911 | } |
| 912 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 913 | static int wm8960_probe(struct snd_soc_codec *codec) |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 914 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 915 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
| 916 | struct wm8960_data *pdata = dev_get_platdata(codec->dev); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 917 | int ret; |
| 918 | u16 reg; |
| 919 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 920 | wm8960->set_bias_level = wm8960_set_bias_level_out3; |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 921 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 922 | if (!pdata) { |
| 923 | dev_warn(codec->dev, "No platform data supplied\n"); |
| 924 | } else { |
| 925 | if (pdata->dres > WM8960_DRES_MAX) { |
| 926 | dev_err(codec->dev, "Invalid DRES: %d\n", pdata->dres); |
| 927 | pdata->dres = 0; |
| 928 | } |
Mark Brown | 913d7b4 | 2010-03-03 13:47:03 +0000 | [diff] [blame] | 929 | |
| 930 | if (pdata->capless) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 931 | wm8960->set_bias_level = wm8960_set_bias_level_capless; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 932 | } |
| 933 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 934 | ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8960->control_type); |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 935 | if (ret < 0) { |
| 936 | dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 937 | return ret; |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 938 | } |
| 939 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 940 | ret = wm8960_reset(codec); |
| 941 | if (ret < 0) { |
| 942 | dev_err(codec->dev, "Failed to issue reset\n"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 943 | return ret; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 944 | } |
| 945 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 946 | wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 947 | |
| 948 | /* Latch the update bits */ |
Mark Brown | 17a52fd | 2009-07-05 17:24:50 +0100 | [diff] [blame] | 949 | reg = snd_soc_read(codec, WM8960_LINVOL); |
| 950 | snd_soc_write(codec, WM8960_LINVOL, reg | 0x100); |
| 951 | reg = snd_soc_read(codec, WM8960_RINVOL); |
| 952 | snd_soc_write(codec, WM8960_RINVOL, reg | 0x100); |
| 953 | reg = snd_soc_read(codec, WM8960_LADC); |
| 954 | snd_soc_write(codec, WM8960_LADC, reg | 0x100); |
| 955 | reg = snd_soc_read(codec, WM8960_RADC); |
| 956 | snd_soc_write(codec, WM8960_RADC, reg | 0x100); |
| 957 | reg = snd_soc_read(codec, WM8960_LDAC); |
| 958 | snd_soc_write(codec, WM8960_LDAC, reg | 0x100); |
| 959 | reg = snd_soc_read(codec, WM8960_RDAC); |
| 960 | snd_soc_write(codec, WM8960_RDAC, reg | 0x100); |
| 961 | reg = snd_soc_read(codec, WM8960_LOUT1); |
| 962 | snd_soc_write(codec, WM8960_LOUT1, reg | 0x100); |
| 963 | reg = snd_soc_read(codec, WM8960_ROUT1); |
| 964 | snd_soc_write(codec, WM8960_ROUT1, reg | 0x100); |
| 965 | reg = snd_soc_read(codec, WM8960_LOUT2); |
| 966 | snd_soc_write(codec, WM8960_LOUT2, reg | 0x100); |
| 967 | reg = snd_soc_read(codec, WM8960_ROUT2); |
| 968 | snd_soc_write(codec, WM8960_ROUT2, reg | 0x100); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 969 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 970 | snd_soc_add_controls(codec, wm8960_snd_controls, |
| 971 | ARRAY_SIZE(wm8960_snd_controls)); |
| 972 | wm8960_add_widgets(codec); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 973 | |
| 974 | return 0; |
| 975 | } |
| 976 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 977 | /* power down chip */ |
| 978 | static int wm8960_remove(struct snd_soc_codec *codec) |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 979 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 980 | struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec); |
| 981 | |
| 982 | wm8960->set_bias_level(codec, SND_SOC_BIAS_OFF); |
| 983 | return 0; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 984 | } |
| 985 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 986 | static struct snd_soc_codec_driver soc_codec_dev_wm8960 = { |
| 987 | .probe = wm8960_probe, |
| 988 | .remove = wm8960_remove, |
| 989 | .suspend = wm8960_suspend, |
| 990 | .resume = wm8960_resume, |
| 991 | .set_bias_level = wm8960_set_bias_level, |
| 992 | .reg_cache_size = ARRAY_SIZE(wm8960_reg), |
| 993 | .reg_word_size = sizeof(u16), |
| 994 | .reg_cache_default = wm8960_reg, |
| 995 | }; |
| 996 | |
| 997 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 998 | static __devinit int wm8960_i2c_probe(struct i2c_client *i2c, |
| 999 | const struct i2c_device_id *id) |
| 1000 | { |
| 1001 | struct wm8960_priv *wm8960; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1002 | int ret; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1003 | |
| 1004 | wm8960 = kzalloc(sizeof(struct wm8960_priv), GFP_KERNEL); |
| 1005 | if (wm8960 == NULL) |
| 1006 | return -ENOMEM; |
| 1007 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1008 | i2c_set_clientdata(i2c, wm8960); |
Lars-Peter Clausen | 7f984b5 | 2010-12-28 21:08:57 +0100 | [diff] [blame] | 1009 | wm8960->control_type = SND_SOC_I2C; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1010 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1011 | ret = snd_soc_register_codec(&i2c->dev, |
| 1012 | &soc_codec_dev_wm8960, &wm8960_dai, 1); |
| 1013 | if (ret < 0) |
| 1014 | kfree(wm8960); |
| 1015 | return ret; |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1016 | } |
| 1017 | |
| 1018 | static __devexit int wm8960_i2c_remove(struct i2c_client *client) |
| 1019 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1020 | snd_soc_unregister_codec(&client->dev); |
| 1021 | kfree(i2c_get_clientdata(client)); |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | static const struct i2c_device_id wm8960_i2c_id[] = { |
| 1026 | { "wm8960", 0 }, |
| 1027 | { } |
| 1028 | }; |
| 1029 | MODULE_DEVICE_TABLE(i2c, wm8960_i2c_id); |
| 1030 | |
| 1031 | static struct i2c_driver wm8960_i2c_driver = { |
| 1032 | .driver = { |
Mark Brown | 091edcc | 2011-12-02 22:08:49 +0000 | [diff] [blame^] | 1033 | .name = "wm8960", |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1034 | .owner = THIS_MODULE, |
| 1035 | }, |
| 1036 | .probe = wm8960_i2c_probe, |
| 1037 | .remove = __devexit_p(wm8960_i2c_remove), |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1038 | .id_table = wm8960_i2c_id, |
| 1039 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1040 | #endif |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1041 | |
| 1042 | static int __init wm8960_modinit(void) |
| 1043 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1044 | int ret = 0; |
| 1045 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1046 | ret = i2c_add_driver(&wm8960_i2c_driver); |
| 1047 | if (ret != 0) { |
| 1048 | printk(KERN_ERR "Failed to register WM8960 I2C driver: %d\n", |
| 1049 | ret); |
| 1050 | } |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1051 | #endif |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1052 | return ret; |
| 1053 | } |
| 1054 | module_init(wm8960_modinit); |
| 1055 | |
| 1056 | static void __exit wm8960_exit(void) |
| 1057 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1058 | #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1059 | i2c_del_driver(&wm8960_i2c_driver); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1060 | #endif |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1061 | } |
| 1062 | module_exit(wm8960_exit); |
| 1063 | |
Mark Brown | f2644a2 | 2009-04-07 19:20:14 +0100 | [diff] [blame] | 1064 | MODULE_DESCRIPTION("ASoC WM8960 driver"); |
| 1065 | MODULE_AUTHOR("Liam Girdwood"); |
| 1066 | MODULE_LICENSE("GPL"); |