Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * wm9712.c -- ALSA Soc WM9712 codec support |
| 3 | * |
Mark Brown | 656baae | 2012-05-23 12:39:07 +0100 | [diff] [blame] | 4 | * Copyright 2006-12 Wolfson Microelectronics PLC. |
Liam Girdwood | d331124 | 2008-10-12 13:17:36 +0100 | [diff] [blame] | 5 | * Author: Liam Girdwood <lrg@slimlogic.co.uk> |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2 of the License, or (at your |
| 10 | * option) any later version. |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 15 | #include <linux/module.h> |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/device.h> |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [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> |
Mark Brown | 471280b | 2012-02-01 12:42:59 +0000 | [diff] [blame] | 23 | #include <sound/tlv.h> |
Mark Brown | dbac7cb | 2008-06-11 13:47:09 +0100 | [diff] [blame] | 24 | #include "wm9712.h" |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 25 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 26 | struct wm9712_priv { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 27 | struct snd_ac97 *ac97; |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 28 | unsigned int hp_mixer[2]; |
| 29 | struct mutex lock; |
| 30 | }; |
| 31 | |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 32 | static unsigned int ac97_read(struct snd_soc_codec *codec, |
| 33 | unsigned int reg); |
| 34 | static int ac97_write(struct snd_soc_codec *codec, |
| 35 | unsigned int reg, unsigned int val); |
| 36 | |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 37 | /* |
| 38 | * WM9712 register cache |
| 39 | */ |
| 40 | static const u16 wm9712_reg[] = { |
Mark Brown | 7e48bf6 | 2008-04-28 14:15:28 +0100 | [diff] [blame] | 41 | 0x6174, 0x8000, 0x8000, 0x8000, /* 6 */ |
| 42 | 0x0f0f, 0xaaa0, 0xc008, 0x6808, /* e */ |
| 43 | 0xe808, 0xaaa0, 0xad00, 0x8000, /* 16 */ |
| 44 | 0xe808, 0x3000, 0x8000, 0x0000, /* 1e */ |
| 45 | 0x0000, 0x0000, 0x0000, 0x000f, /* 26 */ |
| 46 | 0x0405, 0x0410, 0xbb80, 0xbb80, /* 2e */ |
| 47 | 0x0000, 0xbb80, 0x0000, 0x0000, /* 36 */ |
| 48 | 0x0000, 0x2000, 0x0000, 0x0000, /* 3e */ |
| 49 | 0x0000, 0x0000, 0x0000, 0x0000, /* 46 */ |
| 50 | 0x0000, 0x0000, 0xf83e, 0xffff, /* 4e */ |
| 51 | 0x0000, 0x0000, 0x0000, 0xf83e, /* 56 */ |
| 52 | 0x0008, 0x0000, 0x0000, 0x0000, /* 5e */ |
| 53 | 0xb032, 0x3e00, 0x0000, 0x0000, /* 66 */ |
| 54 | 0x0000, 0x0000, 0x0000, 0x0000, /* 6e */ |
| 55 | 0x0000, 0x0000, 0x0000, 0x0006, /* 76 */ |
| 56 | 0x0001, 0x0000, 0x574d, 0x4c12, /* 7e */ |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 57 | }; |
| 58 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 59 | #define HPL_MIXER 0x0 |
| 60 | #define HPR_MIXER 0x1 |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 61 | |
| 62 | static const char *wm9712_alc_select[] = {"None", "Left", "Right", "Stereo"}; |
| 63 | static const char *wm9712_alc_mux[] = {"Stereo", "Left", "Right", "None"}; |
| 64 | static const char *wm9712_out3_src[] = {"Left", "VREF", "Left + Right", |
| 65 | "Mono"}; |
| 66 | static const char *wm9712_spk_src[] = {"Speaker Mix", "Headphone Mix"}; |
| 67 | static const char *wm9712_rec_adc[] = {"Stereo", "Left", "Right", "Mute"}; |
| 68 | static const char *wm9712_base[] = {"Linear Control", "Adaptive Boost"}; |
| 69 | static const char *wm9712_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; |
| 70 | static const char *wm9712_mic[] = {"Mic 1", "Differential", "Mic 2", |
| 71 | "Stereo"}; |
| 72 | static const char *wm9712_rec_sel[] = {"Mic", "NC", "NC", "Speaker Mixer", |
| 73 | "Line", "Headphone Mixer", "Phone Mixer", "Phone"}; |
| 74 | static const char *wm9712_ng_type[] = {"Constant Gain", "Mute"}; |
| 75 | static const char *wm9712_diff_sel[] = {"Mic", "Line"}; |
| 76 | |
Mark Brown | 471280b | 2012-02-01 12:42:59 +0000 | [diff] [blame] | 77 | static const DECLARE_TLV_DB_SCALE(main_tlv, -3450, 150, 0); |
| 78 | static const DECLARE_TLV_DB_SCALE(boost_tlv, 0, 2000, 0); |
| 79 | |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 80 | static const struct soc_enum wm9712_enum[] = { |
| 81 | SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9712_alc_select), |
| 82 | SOC_ENUM_SINGLE(AC97_VIDEO, 12, 4, wm9712_alc_mux), |
| 83 | SOC_ENUM_SINGLE(AC97_AUX, 9, 4, wm9712_out3_src), |
| 84 | SOC_ENUM_SINGLE(AC97_AUX, 8, 2, wm9712_spk_src), |
| 85 | SOC_ENUM_SINGLE(AC97_REC_SEL, 12, 4, wm9712_rec_adc), |
| 86 | SOC_ENUM_SINGLE(AC97_MASTER_TONE, 15, 2, wm9712_base), |
| 87 | SOC_ENUM_DOUBLE(AC97_REC_GAIN, 14, 6, 2, wm9712_rec_gain), |
| 88 | SOC_ENUM_SINGLE(AC97_MIC, 5, 4, wm9712_mic), |
| 89 | SOC_ENUM_SINGLE(AC97_REC_SEL, 8, 8, wm9712_rec_sel), |
| 90 | SOC_ENUM_SINGLE(AC97_REC_SEL, 0, 8, wm9712_rec_sel), |
| 91 | SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9712_ng_type), |
| 92 | SOC_ENUM_SINGLE(0x5c, 8, 2, wm9712_diff_sel), |
| 93 | }; |
| 94 | |
| 95 | static const struct snd_kcontrol_new wm9712_snd_ac97_controls[] = { |
| 96 | SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1), |
| 97 | SOC_SINGLE("Speaker Playback Switch", AC97_MASTER, 15, 1, 1), |
| 98 | SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1), |
Mark Brown | 7e48bf6 | 2008-04-28 14:15:28 +0100 | [diff] [blame] | 99 | SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1), |
Liam Girdwood | 53ae519 | 2007-02-14 15:23:57 +0100 | [diff] [blame] | 100 | SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 101 | |
| 102 | SOC_SINGLE("Speaker Playback ZC Switch", AC97_MASTER, 7, 1, 0), |
| 103 | SOC_SINGLE("Speaker Playback Invert Switch", AC97_MASTER, 6, 1, 0), |
| 104 | SOC_SINGLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 7, 1, 0), |
| 105 | SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_MONO, 7, 1, 0), |
Mike Rapoport | 18fe4ac | 2007-10-22 17:41:08 +0200 | [diff] [blame] | 106 | SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1), |
| 107 | SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 108 | |
| 109 | SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), |
| 110 | SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), |
| 111 | SOC_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0), |
| 112 | SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), |
| 113 | SOC_ENUM("ALC Function", wm9712_enum[0]), |
| 114 | SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0), |
| 115 | SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 1), |
| 116 | SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), |
| 117 | SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), |
| 118 | SOC_ENUM("ALC NG Type", wm9712_enum[10]), |
| 119 | SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 1), |
| 120 | |
| 121 | SOC_SINGLE("Mic Headphone Volume", AC97_VIDEO, 12, 7, 1), |
| 122 | SOC_SINGLE("ALC Headphone Volume", AC97_VIDEO, 7, 7, 1), |
| 123 | |
| 124 | SOC_SINGLE("Out3 Switch", AC97_AUX, 15, 1, 1), |
| 125 | SOC_SINGLE("Out3 ZC Switch", AC97_AUX, 7, 1, 1), |
| 126 | SOC_SINGLE("Out3 Volume", AC97_AUX, 0, 31, 1), |
| 127 | |
| 128 | SOC_SINGLE("PCBeep Bypass Headphone Volume", AC97_PC_BEEP, 12, 7, 1), |
| 129 | SOC_SINGLE("PCBeep Bypass Speaker Volume", AC97_PC_BEEP, 8, 7, 1), |
| 130 | SOC_SINGLE("PCBeep Bypass Phone Volume", AC97_PC_BEEP, 4, 7, 1), |
| 131 | |
| 132 | SOC_SINGLE("Aux Playback Headphone Volume", AC97_CD, 12, 7, 1), |
| 133 | SOC_SINGLE("Aux Playback Speaker Volume", AC97_CD, 8, 7, 1), |
| 134 | SOC_SINGLE("Aux Playback Phone Volume", AC97_CD, 4, 7, 1), |
| 135 | |
Joe Sauer | 7570f29 | 2008-01-10 14:34:56 +0100 | [diff] [blame] | 136 | SOC_SINGLE("Phone Volume", AC97_PHONE, 0, 15, 1), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 137 | SOC_DOUBLE("Line Capture Volume", AC97_LINE, 8, 0, 31, 1), |
| 138 | |
Mark Brown | 3eadd88 | 2012-08-22 17:30:13 +0100 | [diff] [blame] | 139 | SOC_SINGLE_TLV("Capture Boost Switch", AC97_REC_SEL, 14, 1, 0, boost_tlv), |
| 140 | SOC_SINGLE_TLV("Capture to Phone Boost Switch", AC97_REC_SEL, 11, 1, 1, |
| 141 | boost_tlv), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 142 | |
| 143 | SOC_SINGLE("3D Upper Cut-off Switch", AC97_3D_CONTROL, 5, 1, 1), |
| 144 | SOC_SINGLE("3D Lower Cut-off Switch", AC97_3D_CONTROL, 4, 1, 1), |
| 145 | SOC_SINGLE("3D Playback Volume", AC97_3D_CONTROL, 0, 15, 0), |
| 146 | |
| 147 | SOC_ENUM("Bass Control", wm9712_enum[5]), |
| 148 | SOC_SINGLE("Bass Cut-off Switch", AC97_MASTER_TONE, 12, 1, 1), |
| 149 | SOC_SINGLE("Tone Cut-off Switch", AC97_MASTER_TONE, 4, 1, 1), |
| 150 | SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_MASTER_TONE, 6, 1, 0), |
Mike Rapoport | 18fe4ac | 2007-10-22 17:41:08 +0200 | [diff] [blame] | 151 | SOC_SINGLE("Bass Volume", AC97_MASTER_TONE, 8, 15, 1), |
| 152 | SOC_SINGLE("Treble Volume", AC97_MASTER_TONE, 0, 15, 1), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 153 | |
Mark Brown | 689185b | 2012-07-31 18:37:29 +0100 | [diff] [blame] | 154 | SOC_SINGLE("Capture Switch", AC97_REC_GAIN, 15, 1, 1), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 155 | SOC_ENUM("Capture Volume Steps", wm9712_enum[6]), |
Mark Brown | 28c42c2 | 2012-07-31 18:37:28 +0100 | [diff] [blame] | 156 | SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 63, 0), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 157 | SOC_SINGLE("Capture ZC Switch", AC97_REC_GAIN, 7, 1, 0), |
| 158 | |
Mark Brown | 471280b | 2012-02-01 12:42:59 +0000 | [diff] [blame] | 159 | SOC_SINGLE_TLV("Mic 1 Volume", AC97_MIC, 8, 31, 1, main_tlv), |
| 160 | SOC_SINGLE_TLV("Mic 2 Volume", AC97_MIC, 0, 31, 1, main_tlv), |
| 161 | SOC_SINGLE_TLV("Mic Boost Volume", AC97_MIC, 7, 1, 0, boost_tlv), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 162 | }; |
| 163 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 164 | static const unsigned int wm9712_mixer_mute_regs[] = { |
| 165 | AC97_VIDEO, |
| 166 | AC97_PCM, |
| 167 | AC97_LINE, |
| 168 | AC97_PHONE, |
| 169 | AC97_CD, |
| 170 | AC97_PC_BEEP, |
| 171 | }; |
| 172 | |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 173 | /* We have to create a fake left and right HP mixers because |
| 174 | * the codec only has a single control that is shared by both channels. |
| 175 | * This makes it impossible to determine the audio path. |
| 176 | */ |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 177 | static int wm9712_hp_mixer_put(struct snd_kcontrol *kcontrol, |
| 178 | struct snd_ctl_elem_value *ucontrol) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 179 | { |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 180 | struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); |
| 181 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); |
| 182 | struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); |
Takashi Iwai | 4b0b669 | 2015-03-10 12:39:15 +0100 | [diff] [blame] | 183 | unsigned int val = ucontrol->value.integer.value[0]; |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 184 | struct soc_mixer_control *mc = |
| 185 | (struct soc_mixer_control *)kcontrol->private_value; |
| 186 | unsigned int mixer, mask, shift, old; |
| 187 | struct snd_soc_dapm_update update; |
| 188 | bool change; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 189 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 190 | mixer = mc->shift >> 8; |
| 191 | shift = mc->shift & 0xff; |
| 192 | mask = 1 << shift; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 193 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 194 | mutex_lock(&wm9712->lock); |
| 195 | old = wm9712->hp_mixer[mixer]; |
Takashi Iwai | 4b0b669 | 2015-03-10 12:39:15 +0100 | [diff] [blame] | 196 | if (ucontrol->value.integer.value[0]) |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 197 | wm9712->hp_mixer[mixer] |= mask; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 198 | else |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 199 | wm9712->hp_mixer[mixer] &= ~mask; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 200 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 201 | change = old != wm9712->hp_mixer[mixer]; |
| 202 | if (change) { |
| 203 | update.kcontrol = kcontrol; |
| 204 | update.reg = wm9712_mixer_mute_regs[shift]; |
| 205 | update.mask = 0x8000; |
| 206 | if ((wm9712->hp_mixer[0] & mask) || |
| 207 | (wm9712->hp_mixer[1] & mask)) |
| 208 | update.val = 0x0; |
| 209 | else |
| 210 | update.val = 0x8000; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 211 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 212 | snd_soc_dapm_mixer_update_power(dapm, kcontrol, val, |
| 213 | &update); |
| 214 | } |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 215 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 216 | mutex_unlock(&wm9712->lock); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 217 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 218 | return change; |
| 219 | } |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 220 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 221 | static int wm9712_hp_mixer_get(struct snd_kcontrol *kcontrol, |
| 222 | struct snd_ctl_elem_value *ucontrol) |
| 223 | { |
| 224 | struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); |
| 225 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); |
| 226 | struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); |
| 227 | struct soc_mixer_control *mc = |
| 228 | (struct soc_mixer_control *)kcontrol->private_value; |
| 229 | unsigned int shift, mixer; |
| 230 | |
| 231 | mixer = mc->shift >> 8; |
| 232 | shift = mc->shift & 0xff; |
| 233 | |
Takashi Iwai | 4b0b669 | 2015-03-10 12:39:15 +0100 | [diff] [blame] | 234 | ucontrol->value.integer.value[0] = |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 235 | (wm9712->hp_mixer[mixer] >> shift) & 1; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 240 | #define WM9712_HP_MIXER_CTRL(xname, xmixer, xshift) { \ |
| 241 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 242 | .info = snd_soc_info_volsw, \ |
| 243 | .get = wm9712_hp_mixer_get, .put = wm9712_hp_mixer_put, \ |
| 244 | .private_value = SOC_SINGLE_VALUE(SND_SOC_NOPM, \ |
| 245 | (xmixer << 8) | xshift, 1, 0, 0) \ |
| 246 | } |
| 247 | |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 248 | /* Left Headphone Mixers */ |
| 249 | static const struct snd_kcontrol_new wm9712_hpl_mixer_controls[] = { |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 250 | WM9712_HP_MIXER_CTRL("PCBeep Bypass Switch", HPL_MIXER, 5), |
| 251 | WM9712_HP_MIXER_CTRL("Aux Playback Switch", HPL_MIXER, 4), |
| 252 | WM9712_HP_MIXER_CTRL("Phone Bypass Switch", HPL_MIXER, 3), |
| 253 | WM9712_HP_MIXER_CTRL("Line Bypass Switch", HPL_MIXER, 2), |
| 254 | WM9712_HP_MIXER_CTRL("PCM Playback Switch", HPL_MIXER, 1), |
| 255 | WM9712_HP_MIXER_CTRL("Mic Sidetone Switch", HPL_MIXER, 0), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 256 | }; |
| 257 | |
| 258 | /* Right Headphone Mixers */ |
| 259 | static const struct snd_kcontrol_new wm9712_hpr_mixer_controls[] = { |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 260 | WM9712_HP_MIXER_CTRL("PCBeep Bypass Switch", HPR_MIXER, 5), |
| 261 | WM9712_HP_MIXER_CTRL("Aux Playback Switch", HPR_MIXER, 4), |
| 262 | WM9712_HP_MIXER_CTRL("Phone Bypass Switch", HPR_MIXER, 3), |
| 263 | WM9712_HP_MIXER_CTRL("Line Bypass Switch", HPR_MIXER, 2), |
| 264 | WM9712_HP_MIXER_CTRL("PCM Playback Switch", HPR_MIXER, 1), |
| 265 | WM9712_HP_MIXER_CTRL("Mic Sidetone Switch", HPR_MIXER, 0), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 266 | }; |
| 267 | |
| 268 | /* Speaker Mixer */ |
| 269 | static const struct snd_kcontrol_new wm9712_speaker_mixer_controls[] = { |
| 270 | SOC_DAPM_SINGLE("PCBeep Bypass Switch", AC97_PC_BEEP, 11, 1, 1), |
| 271 | SOC_DAPM_SINGLE("Aux Playback Switch", AC97_CD, 11, 1, 1), |
| 272 | SOC_DAPM_SINGLE("Phone Bypass Switch", AC97_PHONE, 14, 1, 1), |
| 273 | SOC_DAPM_SINGLE("Line Bypass Switch", AC97_LINE, 14, 1, 1), |
| 274 | SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PCM, 14, 1, 1), |
| 275 | }; |
| 276 | |
| 277 | /* Phone Mixer */ |
| 278 | static const struct snd_kcontrol_new wm9712_phone_mixer_controls[] = { |
| 279 | SOC_DAPM_SINGLE("PCBeep Bypass Switch", AC97_PC_BEEP, 7, 1, 1), |
| 280 | SOC_DAPM_SINGLE("Aux Playback Switch", AC97_CD, 7, 1, 1), |
| 281 | SOC_DAPM_SINGLE("Line Bypass Switch", AC97_LINE, 13, 1, 1), |
| 282 | SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PCM, 13, 1, 1), |
| 283 | SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_MIC, 14, 1, 1), |
| 284 | SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_MIC, 13, 1, 1), |
| 285 | }; |
| 286 | |
| 287 | /* ALC headphone mux */ |
| 288 | static const struct snd_kcontrol_new wm9712_alc_mux_controls = |
| 289 | SOC_DAPM_ENUM("Route", wm9712_enum[1]); |
| 290 | |
| 291 | /* out 3 mux */ |
| 292 | static const struct snd_kcontrol_new wm9712_out3_mux_controls = |
| 293 | SOC_DAPM_ENUM("Route", wm9712_enum[2]); |
| 294 | |
| 295 | /* spk mux */ |
| 296 | static const struct snd_kcontrol_new wm9712_spk_mux_controls = |
| 297 | SOC_DAPM_ENUM("Route", wm9712_enum[3]); |
| 298 | |
| 299 | /* Capture to Phone mux */ |
| 300 | static const struct snd_kcontrol_new wm9712_capture_phone_mux_controls = |
| 301 | SOC_DAPM_ENUM("Route", wm9712_enum[4]); |
| 302 | |
| 303 | /* Capture left select */ |
| 304 | static const struct snd_kcontrol_new wm9712_capture_selectl_controls = |
| 305 | SOC_DAPM_ENUM("Route", wm9712_enum[8]); |
| 306 | |
| 307 | /* Capture right select */ |
| 308 | static const struct snd_kcontrol_new wm9712_capture_selectr_controls = |
| 309 | SOC_DAPM_ENUM("Route", wm9712_enum[9]); |
| 310 | |
| 311 | /* Mic select */ |
| 312 | static const struct snd_kcontrol_new wm9712_mic_src_controls = |
Mark Brown | ccf7958 | 2012-08-16 22:36:04 +0100 | [diff] [blame] | 313 | SOC_DAPM_ENUM("Mic Source Select", wm9712_enum[7]); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 314 | |
| 315 | /* diff select */ |
| 316 | static const struct snd_kcontrol_new wm9712_diff_sel_controls = |
| 317 | SOC_DAPM_ENUM("Route", wm9712_enum[11]); |
| 318 | |
| 319 | static const struct snd_soc_dapm_widget wm9712_dapm_widgets[] = { |
| 320 | SND_SOC_DAPM_MUX("ALC Sidetone Mux", SND_SOC_NOPM, 0, 0, |
| 321 | &wm9712_alc_mux_controls), |
| 322 | SND_SOC_DAPM_MUX("Out3 Mux", SND_SOC_NOPM, 0, 0, |
| 323 | &wm9712_out3_mux_controls), |
| 324 | SND_SOC_DAPM_MUX("Speaker Mux", SND_SOC_NOPM, 0, 0, |
| 325 | &wm9712_spk_mux_controls), |
| 326 | SND_SOC_DAPM_MUX("Capture Phone Mux", SND_SOC_NOPM, 0, 0, |
| 327 | &wm9712_capture_phone_mux_controls), |
| 328 | SND_SOC_DAPM_MUX("Left Capture Select", SND_SOC_NOPM, 0, 0, |
| 329 | &wm9712_capture_selectl_controls), |
| 330 | SND_SOC_DAPM_MUX("Right Capture Select", SND_SOC_NOPM, 0, 0, |
| 331 | &wm9712_capture_selectr_controls), |
Mark Brown | ccf7958 | 2012-08-16 22:36:04 +0100 | [diff] [blame] | 332 | SND_SOC_DAPM_MUX("Left Mic Select Source", SND_SOC_NOPM, 0, 0, |
| 333 | &wm9712_mic_src_controls), |
| 334 | SND_SOC_DAPM_MUX("Right Mic Select Source", SND_SOC_NOPM, 0, 0, |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 335 | &wm9712_mic_src_controls), |
| 336 | SND_SOC_DAPM_MUX("Differential Source", SND_SOC_NOPM, 0, 0, |
| 337 | &wm9712_diff_sel_controls), |
| 338 | SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 339 | SND_SOC_DAPM_MIXER("Left HP Mixer", AC97_INT_PAGING, 9, 1, |
| 340 | &wm9712_hpl_mixer_controls[0], ARRAY_SIZE(wm9712_hpl_mixer_controls)), |
| 341 | SND_SOC_DAPM_MIXER("Right HP Mixer", AC97_INT_PAGING, 8, 1, |
| 342 | &wm9712_hpr_mixer_controls[0], ARRAY_SIZE(wm9712_hpr_mixer_controls)), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 343 | SND_SOC_DAPM_MIXER("Phone Mixer", AC97_INT_PAGING, 6, 1, |
| 344 | &wm9712_phone_mixer_controls[0], ARRAY_SIZE(wm9712_phone_mixer_controls)), |
| 345 | SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_INT_PAGING, 7, 1, |
| 346 | &wm9712_speaker_mixer_controls[0], |
| 347 | ARRAY_SIZE(wm9712_speaker_mixer_controls)), |
| 348 | SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 349 | SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_INT_PAGING, 14, 1), |
| 350 | SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_INT_PAGING, 13, 1), |
| 351 | SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", SND_SOC_NOPM, 0, 0), |
| 352 | SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", AC97_INT_PAGING, 12, 1), |
| 353 | SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", AC97_INT_PAGING, 11, 1), |
| 354 | SND_SOC_DAPM_PGA("Headphone PGA", AC97_INT_PAGING, 4, 1, NULL, 0), |
| 355 | SND_SOC_DAPM_PGA("Speaker PGA", AC97_INT_PAGING, 3, 1, NULL, 0), |
| 356 | SND_SOC_DAPM_PGA("Out 3 PGA", AC97_INT_PAGING, 5, 1, NULL, 0), |
| 357 | SND_SOC_DAPM_PGA("Line PGA", AC97_INT_PAGING, 2, 1, NULL, 0), |
| 358 | SND_SOC_DAPM_PGA("Phone PGA", AC97_INT_PAGING, 1, 1, NULL, 0), |
| 359 | SND_SOC_DAPM_PGA("Mic PGA", AC97_INT_PAGING, 0, 1, NULL, 0), |
Mark Brown | ccf7958 | 2012-08-16 22:36:04 +0100 | [diff] [blame] | 360 | SND_SOC_DAPM_PGA("Differential Mic", SND_SOC_NOPM, 0, 0, NULL, 0), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 361 | SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_INT_PAGING, 10, 1), |
| 362 | SND_SOC_DAPM_OUTPUT("MONOOUT"), |
| 363 | SND_SOC_DAPM_OUTPUT("HPOUTL"), |
| 364 | SND_SOC_DAPM_OUTPUT("HPOUTR"), |
| 365 | SND_SOC_DAPM_OUTPUT("LOUT2"), |
| 366 | SND_SOC_DAPM_OUTPUT("ROUT2"), |
| 367 | SND_SOC_DAPM_OUTPUT("OUT3"), |
| 368 | SND_SOC_DAPM_INPUT("LINEINL"), |
| 369 | SND_SOC_DAPM_INPUT("LINEINR"), |
| 370 | SND_SOC_DAPM_INPUT("PHONE"), |
| 371 | SND_SOC_DAPM_INPUT("PCBEEP"), |
| 372 | SND_SOC_DAPM_INPUT("MIC1"), |
| 373 | SND_SOC_DAPM_INPUT("MIC2"), |
| 374 | }; |
| 375 | |
Lu Guanqun | 9833477 | 2011-03-30 21:53:12 +0800 | [diff] [blame] | 376 | static const struct snd_soc_dapm_route wm9712_audio_map[] = { |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 377 | /* virtual mixer - mixes left & right channels for spk and mono */ |
| 378 | {"AC97 Mixer", NULL, "Left DAC"}, |
| 379 | {"AC97 Mixer", NULL, "Right DAC"}, |
| 380 | |
| 381 | /* Left HP mixer */ |
| 382 | {"Left HP Mixer", "PCBeep Bypass Switch", "PCBEEP"}, |
| 383 | {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 384 | {"Left HP Mixer", "Phone Bypass Switch", "Phone PGA"}, |
| 385 | {"Left HP Mixer", "Line Bypass Switch", "Line PGA"}, |
| 386 | {"Left HP Mixer", "PCM Playback Switch", "Left DAC"}, |
| 387 | {"Left HP Mixer", "Mic Sidetone Switch", "Mic PGA"}, |
| 388 | {"Left HP Mixer", NULL, "ALC Sidetone Mux"}, |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 389 | |
| 390 | /* Right HP mixer */ |
| 391 | {"Right HP Mixer", "PCBeep Bypass Switch", "PCBEEP"}, |
| 392 | {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 393 | {"Right HP Mixer", "Phone Bypass Switch", "Phone PGA"}, |
| 394 | {"Right HP Mixer", "Line Bypass Switch", "Line PGA"}, |
| 395 | {"Right HP Mixer", "PCM Playback Switch", "Right DAC"}, |
| 396 | {"Right HP Mixer", "Mic Sidetone Switch", "Mic PGA"}, |
| 397 | {"Right HP Mixer", NULL, "ALC Sidetone Mux"}, |
| 398 | |
| 399 | /* speaker mixer */ |
| 400 | {"Speaker Mixer", "PCBeep Bypass Switch", "PCBEEP"}, |
| 401 | {"Speaker Mixer", "Line Bypass Switch", "Line PGA"}, |
| 402 | {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"}, |
| 403 | {"Speaker Mixer", "Phone Bypass Switch", "Phone PGA"}, |
| 404 | {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 405 | |
| 406 | /* Phone mixer */ |
| 407 | {"Phone Mixer", "PCBeep Bypass Switch", "PCBEEP"}, |
| 408 | {"Phone Mixer", "Line Bypass Switch", "Line PGA"}, |
| 409 | {"Phone Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 410 | {"Phone Mixer", "PCM Playback Switch", "AC97 Mixer"}, |
| 411 | {"Phone Mixer", "Mic 1 Sidetone Switch", "Mic PGA"}, |
| 412 | {"Phone Mixer", "Mic 2 Sidetone Switch", "Mic PGA"}, |
| 413 | |
| 414 | /* inputs */ |
| 415 | {"Line PGA", NULL, "LINEINL"}, |
| 416 | {"Line PGA", NULL, "LINEINR"}, |
| 417 | {"Phone PGA", NULL, "PHONE"}, |
| 418 | {"Mic PGA", NULL, "MIC1"}, |
| 419 | {"Mic PGA", NULL, "MIC2"}, |
| 420 | |
Mark Brown | ccf7958 | 2012-08-16 22:36:04 +0100 | [diff] [blame] | 421 | /* microphones */ |
| 422 | {"Differential Mic", NULL, "MIC1"}, |
| 423 | {"Differential Mic", NULL, "MIC2"}, |
| 424 | {"Left Mic Select Source", "Mic 1", "MIC1"}, |
| 425 | {"Left Mic Select Source", "Mic 2", "MIC2"}, |
| 426 | {"Left Mic Select Source", "Stereo", "MIC1"}, |
| 427 | {"Left Mic Select Source", "Differential", "Differential Mic"}, |
| 428 | {"Right Mic Select Source", "Mic 1", "MIC1"}, |
| 429 | {"Right Mic Select Source", "Mic 2", "MIC2"}, |
| 430 | {"Right Mic Select Source", "Stereo", "MIC2"}, |
| 431 | {"Right Mic Select Source", "Differential", "Differential Mic"}, |
| 432 | |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 433 | /* left capture selector */ |
| 434 | {"Left Capture Select", "Mic", "MIC1"}, |
| 435 | {"Left Capture Select", "Speaker Mixer", "Speaker Mixer"}, |
| 436 | {"Left Capture Select", "Line", "LINEINL"}, |
| 437 | {"Left Capture Select", "Headphone Mixer", "Left HP Mixer"}, |
| 438 | {"Left Capture Select", "Phone Mixer", "Phone Mixer"}, |
| 439 | {"Left Capture Select", "Phone", "PHONE"}, |
| 440 | |
| 441 | /* right capture selector */ |
| 442 | {"Right Capture Select", "Mic", "MIC2"}, |
| 443 | {"Right Capture Select", "Speaker Mixer", "Speaker Mixer"}, |
| 444 | {"Right Capture Select", "Line", "LINEINR"}, |
| 445 | {"Right Capture Select", "Headphone Mixer", "Right HP Mixer"}, |
| 446 | {"Right Capture Select", "Phone Mixer", "Phone Mixer"}, |
| 447 | {"Right Capture Select", "Phone", "PHONE"}, |
| 448 | |
| 449 | /* ALC Sidetone */ |
| 450 | {"ALC Sidetone Mux", "Stereo", "Left Capture Select"}, |
| 451 | {"ALC Sidetone Mux", "Stereo", "Right Capture Select"}, |
| 452 | {"ALC Sidetone Mux", "Left", "Left Capture Select"}, |
| 453 | {"ALC Sidetone Mux", "Right", "Right Capture Select"}, |
| 454 | |
| 455 | /* ADC's */ |
| 456 | {"Left ADC", NULL, "Left Capture Select"}, |
| 457 | {"Right ADC", NULL, "Right Capture Select"}, |
| 458 | |
| 459 | /* outputs */ |
| 460 | {"MONOOUT", NULL, "Phone Mixer"}, |
| 461 | {"HPOUTL", NULL, "Headphone PGA"}, |
| 462 | {"Headphone PGA", NULL, "Left HP Mixer"}, |
| 463 | {"HPOUTR", NULL, "Headphone PGA"}, |
| 464 | {"Headphone PGA", NULL, "Right HP Mixer"}, |
| 465 | |
Marek Vasut | 9432484 | 2008-07-20 17:36:20 +0200 | [diff] [blame] | 466 | /* mono mixer */ |
| 467 | {"Mono Mixer", NULL, "Left HP Mixer"}, |
| 468 | {"Mono Mixer", NULL, "Right HP Mixer"}, |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 469 | |
| 470 | /* Out3 Mux */ |
| 471 | {"Out3 Mux", "Left", "Left HP Mixer"}, |
| 472 | {"Out3 Mux", "Mono", "Phone Mixer"}, |
Marek Vasut | 9432484 | 2008-07-20 17:36:20 +0200 | [diff] [blame] | 473 | {"Out3 Mux", "Left + Right", "Mono Mixer"}, |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 474 | {"Out 3 PGA", NULL, "Out3 Mux"}, |
| 475 | {"OUT3", NULL, "Out 3 PGA"}, |
| 476 | |
| 477 | /* speaker Mux */ |
| 478 | {"Speaker Mux", "Speaker Mix", "Speaker Mixer"}, |
Marek Vasut | 9432484 | 2008-07-20 17:36:20 +0200 | [diff] [blame] | 479 | {"Speaker Mux", "Headphone Mix", "Mono Mixer"}, |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 480 | {"Speaker PGA", NULL, "Speaker Mux"}, |
| 481 | {"LOUT2", NULL, "Speaker PGA"}, |
| 482 | {"ROUT2", NULL, "Speaker PGA"}, |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 483 | }; |
| 484 | |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 485 | static unsigned int ac97_read(struct snd_soc_codec *codec, |
| 486 | unsigned int reg) |
| 487 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 488 | struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 489 | u16 *cache = codec->reg_cache; |
| 490 | |
| 491 | if (reg == AC97_RESET || reg == AC97_GPIO_STATUS || |
| 492 | reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 || |
| 493 | reg == AC97_REC_GAIN) |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 494 | return soc_ac97_ops->read(wm9712->ac97, reg); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 495 | else { |
| 496 | reg = reg >> 1; |
| 497 | |
Ian Molton | 91432e9 | 2009-01-17 17:44:23 +0000 | [diff] [blame] | 498 | if (reg >= (ARRAY_SIZE(wm9712_reg))) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 499 | return -EIO; |
| 500 | |
| 501 | return cache[reg]; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, |
| 506 | unsigned int val) |
| 507 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 508 | struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 509 | u16 *cache = codec->reg_cache; |
| 510 | |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 511 | soc_ac97_ops->write(wm9712->ac97, reg, val); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 512 | reg = reg >> 1; |
Ian Molton | 91432e9 | 2009-01-17 17:44:23 +0000 | [diff] [blame] | 513 | if (reg < (ARRAY_SIZE(wm9712_reg))) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 514 | cache[reg] = val; |
| 515 | |
| 516 | return 0; |
| 517 | } |
| 518 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 519 | static int ac97_prepare(struct snd_pcm_substream *substream, |
| 520 | struct snd_soc_dai *dai) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 521 | { |
Mark Brown | e6968a1 | 2012-04-04 15:58:16 +0100 | [diff] [blame] | 522 | struct snd_soc_codec *codec = dai->codec; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 523 | int reg; |
| 524 | u16 vra; |
Fabio Estevam | b46ac30 | 2012-04-10 18:33:07 -0300 | [diff] [blame] | 525 | struct snd_pcm_runtime *runtime = substream->runtime; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 526 | |
| 527 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); |
| 528 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); |
| 529 | |
| 530 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 531 | reg = AC97_PCM_FRONT_DAC_RATE; |
| 532 | else |
| 533 | reg = AC97_PCM_LR_ADC_RATE; |
| 534 | |
| 535 | return ac97_write(codec, reg, runtime->rate); |
| 536 | } |
| 537 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 538 | static int ac97_aux_prepare(struct snd_pcm_substream *substream, |
| 539 | struct snd_soc_dai *dai) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 540 | { |
Mark Brown | e6968a1 | 2012-04-04 15:58:16 +0100 | [diff] [blame] | 541 | struct snd_soc_codec *codec = dai->codec; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 542 | u16 vra, xsle; |
Fabio Estevam | b46ac30 | 2012-04-10 18:33:07 -0300 | [diff] [blame] | 543 | struct snd_pcm_runtime *runtime = substream->runtime; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 544 | |
| 545 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); |
| 546 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); |
| 547 | xsle = ac97_read(codec, AC97_PCI_SID); |
| 548 | ac97_write(codec, AC97_PCI_SID, xsle | 0x8000); |
| 549 | |
| 550 | if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) |
| 551 | return -ENODEV; |
| 552 | |
| 553 | return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate); |
| 554 | } |
| 555 | |
Liam Girdwood | cbe83b1 | 2007-02-02 17:16:02 +0100 | [diff] [blame] | 556 | #define WM9712_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
Mark Brown | 7e48bf6 | 2008-04-28 14:15:28 +0100 | [diff] [blame] | 557 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\ |
| 558 | SNDRV_PCM_RATE_48000) |
Liam Girdwood | cbe83b1 | 2007-02-02 17:16:02 +0100 | [diff] [blame] | 559 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 560 | static const struct snd_soc_dai_ops wm9712_dai_ops_hifi = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 561 | .prepare = ac97_prepare, |
| 562 | }; |
| 563 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 564 | static const struct snd_soc_dai_ops wm9712_dai_ops_aux = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 565 | .prepare = ac97_aux_prepare, |
| 566 | }; |
| 567 | |
Mark Brown | 0daaf7e | 2010-09-06 18:56:03 +0100 | [diff] [blame] | 568 | static struct snd_soc_dai_driver wm9712_dai[] = { |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 569 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 570 | .name = "wm9712-hifi", |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 571 | .playback = { |
| 572 | .stream_name = "HiFi Playback", |
| 573 | .channels_min = 1, |
Liam Girdwood | cbe83b1 | 2007-02-02 17:16:02 +0100 | [diff] [blame] | 574 | .channels_max = 2, |
| 575 | .rates = WM9712_AC97_RATES, |
Mark Brown | 33f503c | 2009-05-02 12:24:55 +0100 | [diff] [blame] | 576 | .formats = SND_SOC_STD_AC97_FMTS,}, |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 577 | .capture = { |
| 578 | .stream_name = "HiFi Capture", |
| 579 | .channels_min = 1, |
Liam Girdwood | cbe83b1 | 2007-02-02 17:16:02 +0100 | [diff] [blame] | 580 | .channels_max = 2, |
| 581 | .rates = WM9712_AC97_RATES, |
Mark Brown | 33f503c | 2009-05-02 12:24:55 +0100 | [diff] [blame] | 582 | .formats = SND_SOC_STD_AC97_FMTS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 583 | .ops = &wm9712_dai_ops_hifi, |
Liam Girdwood | cbe83b1 | 2007-02-02 17:16:02 +0100 | [diff] [blame] | 584 | }, |
| 585 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 586 | .name = "wm9712-aux", |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 587 | .playback = { |
| 588 | .stream_name = "Aux Playback", |
| 589 | .channels_min = 1, |
Liam Girdwood | cbe83b1 | 2007-02-02 17:16:02 +0100 | [diff] [blame] | 590 | .channels_max = 1, |
| 591 | .rates = WM9712_AC97_RATES, |
Mark Brown | 33f503c | 2009-05-02 12:24:55 +0100 | [diff] [blame] | 592 | .formats = SND_SOC_STD_AC97_FMTS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 593 | .ops = &wm9712_dai_ops_aux, |
Liam Girdwood | cbe83b1 | 2007-02-02 17:16:02 +0100 | [diff] [blame] | 594 | } |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 595 | }; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 596 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 597 | static int wm9712_set_bias_level(struct snd_soc_codec *codec, |
| 598 | enum snd_soc_bias_level level) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 599 | { |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 600 | switch (level) { |
| 601 | case SND_SOC_BIAS_ON: |
| 602 | case SND_SOC_BIAS_PREPARE: |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 603 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 604 | case SND_SOC_BIAS_STANDBY: |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 605 | ac97_write(codec, AC97_POWERDOWN, 0x0000); |
| 606 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 607 | case SND_SOC_BIAS_OFF: |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 608 | /* disable everything including AC link */ |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 609 | ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); |
| 610 | ac97_write(codec, AC97_POWERDOWN, 0xffff); |
| 611 | break; |
| 612 | } |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | static int wm9712_reset(struct snd_soc_codec *codec, int try_warm) |
| 617 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 618 | struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); |
| 619 | |
Mark Brown | b047e1c | 2013-06-26 12:45:59 +0100 | [diff] [blame] | 620 | if (try_warm && soc_ac97_ops->warm_reset) { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 621 | soc_ac97_ops->warm_reset(wm9712->ac97); |
Mark Brown | abb68c2 | 2008-06-13 16:24:04 +0100 | [diff] [blame] | 622 | if (ac97_read(codec, 0) == wm9712_reg[0]) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 623 | return 1; |
| 624 | } |
| 625 | |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 626 | soc_ac97_ops->reset(wm9712->ac97); |
Mark Brown | b047e1c | 2013-06-26 12:45:59 +0100 | [diff] [blame] | 627 | if (soc_ac97_ops->warm_reset) |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 628 | soc_ac97_ops->warm_reset(wm9712->ac97); |
Mark Brown | abb68c2 | 2008-06-13 16:24:04 +0100 | [diff] [blame] | 629 | if (ac97_read(codec, 0) != wm9712_reg[0]) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 630 | goto err; |
| 631 | return 0; |
| 632 | |
| 633 | err: |
Lars-Peter Clausen | 12ced33 | 2014-10-30 21:01:05 +0100 | [diff] [blame] | 634 | dev_err(codec->dev, "Failed to reset: AC97 link error\n"); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 635 | return -EIO; |
| 636 | } |
| 637 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 638 | static int wm9712_soc_resume(struct snd_soc_codec *codec) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 639 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 640 | struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 641 | int i, ret; |
| 642 | u16 *cache = codec->reg_cache; |
| 643 | |
| 644 | ret = wm9712_reset(codec, 1); |
Lars-Peter Clausen | 12ced33 | 2014-10-30 21:01:05 +0100 | [diff] [blame] | 645 | if (ret < 0) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 646 | return ret; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 647 | |
Lars-Peter Clausen | bd1204c | 2015-04-27 22:13:24 +0200 | [diff] [blame] | 648 | snd_soc_codec_force_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 649 | |
| 650 | if (ret == 0) { |
| 651 | /* Sync reg_cache with the hardware after cold reset */ |
Mark Brown | 7e48bf6 | 2008-04-28 14:15:28 +0100 | [diff] [blame] | 652 | for (i = 2; i < ARRAY_SIZE(wm9712_reg) << 1; i += 2) { |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 653 | if (i == AC97_INT_PAGING || i == AC97_POWERDOWN || |
Mark Brown | 7e48bf6 | 2008-04-28 14:15:28 +0100 | [diff] [blame] | 654 | (i > 0x58 && i != 0x5c)) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 655 | continue; |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 656 | soc_ac97_ops->write(wm9712->ac97, i, cache[i>>1]); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 657 | } |
| 658 | } |
| 659 | |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 660 | return ret; |
| 661 | } |
| 662 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 663 | static int wm9712_soc_probe(struct snd_soc_codec *codec) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 664 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 665 | struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 666 | int ret = 0; |
| 667 | |
Lars-Peter Clausen | f8d71be | 2015-01-23 16:21:37 +0100 | [diff] [blame] | 668 | wm9712->ac97 = snd_soc_alloc_ac97_codec(codec); |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 669 | if (IS_ERR(wm9712->ac97)) { |
| 670 | ret = PTR_ERR(wm9712->ac97); |
| 671 | dev_err(codec->dev, "Failed to register AC97 codec: %d\n", ret); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 672 | return ret; |
Liam Girdwood | e35115a | 2007-01-31 10:02:23 +0100 | [diff] [blame] | 673 | } |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 674 | |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 675 | ret = wm9712_reset(codec, 0); |
Lars-Peter Clausen | 12ced33 | 2014-10-30 21:01:05 +0100 | [diff] [blame] | 676 | if (ret < 0) |
Lars-Peter Clausen | f8d71be | 2015-01-23 16:21:37 +0100 | [diff] [blame] | 677 | goto err_put_device; |
| 678 | |
| 679 | ret = device_add(&wm9712->ac97->dev); |
| 680 | if (ret) |
| 681 | goto err_put_device; |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 682 | |
| 683 | /* set alc mux to none */ |
| 684 | ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000); |
| 685 | |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 686 | return 0; |
| 687 | |
Lars-Peter Clausen | f8d71be | 2015-01-23 16:21:37 +0100 | [diff] [blame] | 688 | err_put_device: |
| 689 | put_device(&wm9712->ac97->dev); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 690 | return ret; |
| 691 | } |
| 692 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 693 | static int wm9712_soc_remove(struct snd_soc_codec *codec) |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 694 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 695 | struct wm9712_priv *wm9712 = snd_soc_codec_get_drvdata(codec); |
| 696 | |
| 697 | snd_soc_free_ac97_codec(wm9712->ac97); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 698 | return 0; |
| 699 | } |
| 700 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 701 | static struct snd_soc_codec_driver soc_codec_dev_wm9712 = { |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 702 | .probe = wm9712_soc_probe, |
| 703 | .remove = wm9712_soc_remove, |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 704 | .resume = wm9712_soc_resume, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 705 | .read = ac97_read, |
| 706 | .write = ac97_write, |
| 707 | .set_bias_level = wm9712_set_bias_level, |
Lars-Peter Clausen | ab492b8 | 2014-11-23 13:37:47 +0100 | [diff] [blame] | 708 | .suspend_bias_off = true, |
Dimitris Papastamos | e5eec34 | 2010-09-10 18:14:56 +0100 | [diff] [blame] | 709 | .reg_cache_size = ARRAY_SIZE(wm9712_reg), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 710 | .reg_word_size = sizeof(u16), |
| 711 | .reg_cache_step = 2, |
| 712 | .reg_cache_default = wm9712_reg, |
Lars-Peter Clausen | 9a812c6 | 2014-10-30 21:01:06 +0100 | [diff] [blame] | 713 | |
| 714 | .controls = wm9712_snd_ac97_controls, |
| 715 | .num_controls = ARRAY_SIZE(wm9712_snd_ac97_controls), |
Lu Guanqun | 9833477 | 2011-03-30 21:53:12 +0800 | [diff] [blame] | 716 | .dapm_widgets = wm9712_dapm_widgets, |
| 717 | .num_dapm_widgets = ARRAY_SIZE(wm9712_dapm_widgets), |
| 718 | .dapm_routes = wm9712_audio_map, |
| 719 | .num_dapm_routes = ARRAY_SIZE(wm9712_audio_map), |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 720 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 721 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 722 | static int wm9712_probe(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 723 | { |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 724 | struct wm9712_priv *wm9712; |
| 725 | |
| 726 | wm9712 = devm_kzalloc(&pdev->dev, sizeof(*wm9712), GFP_KERNEL); |
| 727 | if (wm9712 == NULL) |
| 728 | return -ENOMEM; |
| 729 | |
| 730 | mutex_init(&wm9712->lock); |
| 731 | |
| 732 | platform_set_drvdata(pdev, wm9712); |
| 733 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 734 | return snd_soc_register_codec(&pdev->dev, |
| 735 | &soc_codec_dev_wm9712, wm9712_dai, ARRAY_SIZE(wm9712_dai)); |
| 736 | } |
| 737 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 738 | static int wm9712_remove(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 739 | { |
| 740 | snd_soc_unregister_codec(&pdev->dev); |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | static struct platform_driver wm9712_codec_driver = { |
| 745 | .driver = { |
Mark Brown | 9a37eae | 2012-07-31 18:37:30 +0100 | [diff] [blame] | 746 | .name = "wm9712-codec", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 747 | }, |
| 748 | |
| 749 | .probe = wm9712_probe, |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 750 | .remove = wm9712_remove, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 751 | }; |
| 752 | |
Mark Brown | 5bbcc3c | 2011-11-23 22:52:08 +0000 | [diff] [blame] | 753 | module_platform_driver(wm9712_codec_driver); |
Richard Purdie | 10c5cf3 | 2006-10-06 18:37:32 +0200 | [diff] [blame] | 754 | |
| 755 | MODULE_DESCRIPTION("ASoC WM9711/WM9712 driver"); |
| 756 | MODULE_AUTHOR("Liam Girdwood"); |
| 757 | MODULE_LICENSE("GPL"); |