| 1 |
// SPDX-License-Identifier: GPL-2.0-only |
| 2 |
/* |
| 3 |
* alc5623.c -- alc562[123] ALSA Soc Audio driver |
| 4 |
* |
| 5 |
* Copyright 2008 Realtek Microelectronics |
| 6 |
* Author: flove <[email protected]> Ethan <[email protected]> |
| 7 |
* |
| 8 |
* Copyright 2010 Arnaud Patard <[email protected]> |
| 9 |
* |
| 10 |
* Based on WM8753.c |
| 11 |
*/ |
| 12 |
|
| 13 |
#include <linux/module.h> |
| 14 |
#include <linux/kernel.h> |
| 15 |
#include <linux/init.h> |
| 16 |
#include <linux/delay.h> |
| 17 |
#include <linux/pm.h> |
| 18 |
#include <linux/i2c.h> |
| 19 |
#include <linux/regmap.h> |
| 20 |
#include <linux/slab.h> |
| 21 |
#include <linux/of.h> |
| 22 |
#include <sound/core.h> |
| 23 |
#include <sound/pcm.h> |
| 24 |
#include <sound/pcm_params.h> |
| 25 |
#include <sound/tlv.h> |
| 26 |
#include <sound/soc.h> |
| 27 |
#include <sound/initval.h> |
| 28 |
#include <sound/alc5623.h> |
| 29 |
|
| 30 |
#include "alc5623.h" |
| 31 |
|
| 32 |
static int caps_charge = 2000; |
| 33 |
module_param(caps_charge, int, 0); |
| 34 |
MODULE_PARM_DESC(caps_charge, "ALC5623 cap charge time (msecs)"); |
| 35 |
|
| 36 |
/* codec private data */ |
| 37 |
struct alc5623_priv { |
| 38 |
struct regmap *regmap; |
| 39 |
u8 id; |
| 40 |
unsigned int sysclk; |
| 41 |
unsigned int add_ctrl; |
| 42 |
unsigned int jack_det_ctrl; |
| 43 |
}; |
| 44 |
|
| 45 |
static inline int alc5623_reset(struct snd_soc_component *component) |
| 46 |
{ |
| 47 |
return snd_soc_component_write(component, ALC5623_RESET, 0); |
| 48 |
} |
| 49 |
|
| 50 |
static int amp_mixer_event(struct snd_soc_dapm_widget *w, |
| 51 |
struct snd_kcontrol *kcontrol, int event) |
| 52 |
{ |
| 53 |
struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 54 |
|
| 55 |
/* to power-on/off class-d amp generators/speaker */ |
| 56 |
/* need to write to 'index-46h' register : */ |
| 57 |
/* so write index num (here 0x46) to reg 0x6a */ |
| 58 |
/* and then 0xffff/0 to reg 0x6c */ |
| 59 |
snd_soc_component_write(component, ALC5623_HID_CTRL_INDEX, 0x46); |
| 60 |
|
| 61 |
switch (event) { |
| 62 |
case SND_SOC_DAPM_PRE_PMU: |
| 63 |
snd_soc_component_write(component, ALC5623_HID_CTRL_DATA, 0xFFFF); |
| 64 |
break; |
| 65 |
case SND_SOC_DAPM_POST_PMD: |
| 66 |
snd_soc_component_write(component, ALC5623_HID_CTRL_DATA, 0); |
| 67 |
break; |
| 68 |
} |
| 69 |
|
| 70 |
return 0; |
| 71 |
} |
| 72 |
|
| 73 |
/* |
| 74 |
* ALC5623 Controls |
| 75 |
*/ |
| 76 |
|
| 77 |
static const DECLARE_TLV_DB_SCALE(vol_tlv, -3450, 150, 0); |
| 78 |
static const DECLARE_TLV_DB_SCALE(hp_tlv, -4650, 150, 0); |
| 79 |
static const DECLARE_TLV_DB_SCALE(adc_rec_tlv, -1650, 150, 0); |
| 80 |
static const DECLARE_TLV_DB_RANGE(boost_tlv, |
| 81 |
0, 0, TLV_DB_SCALE_ITEM(0, 0, 0), |
| 82 |
1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0), |
| 83 |
2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0) |
| 84 |
); |
| 85 |
static const DECLARE_TLV_DB_SCALE(dig_tlv, 0, 600, 0); |
| 86 |
|
| 87 |
static const struct snd_kcontrol_new alc5621_vol_snd_controls[] = { |
| 88 |
SOC_DOUBLE_TLV("Speaker Playback Volume", |
| 89 |
ALC5623_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv), |
| 90 |
SOC_DOUBLE("Speaker Playback Switch", |
| 91 |
ALC5623_SPK_OUT_VOL, 15, 7, 1, 1), |
| 92 |
SOC_DOUBLE_TLV("Headphone Playback Volume", |
| 93 |
ALC5623_HP_OUT_VOL, 8, 0, 31, 1, hp_tlv), |
| 94 |
SOC_DOUBLE("Headphone Playback Switch", |
| 95 |
ALC5623_HP_OUT_VOL, 15, 7, 1, 1), |
| 96 |
}; |
| 97 |
|
| 98 |
static const struct snd_kcontrol_new alc5622_vol_snd_controls[] = { |
| 99 |
SOC_DOUBLE_TLV("Speaker Playback Volume", |
| 100 |
ALC5623_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv), |
| 101 |
SOC_DOUBLE("Speaker Playback Switch", |
| 102 |
ALC5623_SPK_OUT_VOL, 15, 7, 1, 1), |
| 103 |
SOC_DOUBLE_TLV("Line Playback Volume", |
| 104 |
ALC5623_HP_OUT_VOL, 8, 0, 31, 1, hp_tlv), |
| 105 |
SOC_DOUBLE("Line Playback Switch", |
| 106 |
ALC5623_HP_OUT_VOL, 15, 7, 1, 1), |
| 107 |
}; |
| 108 |
|
| 109 |
static const struct snd_kcontrol_new alc5623_vol_snd_controls[] = { |
| 110 |
SOC_DOUBLE_TLV("Line Playback Volume", |
| 111 |
ALC5623_SPK_OUT_VOL, 8, 0, 31, 1, hp_tlv), |
| 112 |
SOC_DOUBLE("Line Playback Switch", |
| 113 |
ALC5623_SPK_OUT_VOL, 15, 7, 1, 1), |
| 114 |
SOC_DOUBLE_TLV("Headphone Playback Volume", |
| 115 |
ALC5623_HP_OUT_VOL, 8, 0, 31, 1, hp_tlv), |
| 116 |
SOC_DOUBLE("Headphone Playback Switch", |
| 117 |
ALC5623_HP_OUT_VOL, 15, 7, 1, 1), |
| 118 |
}; |
| 119 |
|
| 120 |
static const struct snd_kcontrol_new alc5623_snd_controls[] = { |
| 121 |
SOC_DOUBLE_TLV("Auxout Playback Volume", |
| 122 |
ALC5623_MONO_AUX_OUT_VOL, 8, 0, 31, 1, hp_tlv), |
| 123 |
SOC_DOUBLE("Auxout Playback Switch", |
| 124 |
ALC5623_MONO_AUX_OUT_VOL, 15, 7, 1, 1), |
| 125 |
SOC_DOUBLE_TLV("PCM Playback Volume", |
| 126 |
ALC5623_STEREO_DAC_VOL, 8, 0, 31, 1, vol_tlv), |
| 127 |
SOC_DOUBLE_TLV("AuxI Capture Volume", |
| 128 |
ALC5623_AUXIN_VOL, 8, 0, 31, 1, vol_tlv), |
| 129 |
SOC_DOUBLE_TLV("LineIn Capture Volume", |
| 130 |
ALC5623_LINE_IN_VOL, 8, 0, 31, 1, vol_tlv), |
| 131 |
SOC_SINGLE_TLV("Mic1 Capture Volume", |
| 132 |
ALC5623_MIC_VOL, 8, 31, 1, vol_tlv), |
| 133 |
SOC_SINGLE_TLV("Mic2 Capture Volume", |
| 134 |
ALC5623_MIC_VOL, 0, 31, 1, vol_tlv), |
| 135 |
SOC_DOUBLE_TLV("Rec Capture Volume", |
| 136 |
ALC5623_ADC_REC_GAIN, 7, 0, 31, 0, adc_rec_tlv), |
| 137 |
SOC_SINGLE_TLV("Mic 1 Boost Volume", |
| 138 |
ALC5623_MIC_CTRL, 10, 2, 0, boost_tlv), |
| 139 |
SOC_SINGLE_TLV("Mic 2 Boost Volume", |
| 140 |
ALC5623_MIC_CTRL, 8, 2, 0, boost_tlv), |
| 141 |
SOC_SINGLE_TLV("Digital Boost Volume", |
| 142 |
ALC5623_ADD_CTRL_REG, 4, 3, 0, dig_tlv), |
| 143 |
}; |
| 144 |
|
| 145 |
/* |
| 146 |
* DAPM Controls |
| 147 |
*/ |
| 148 |
static const struct snd_kcontrol_new alc5623_hp_mixer_controls[] = { |
| 149 |
SOC_DAPM_SINGLE("LI2HP Playback Switch", ALC5623_LINE_IN_VOL, 15, 1, 1), |
| 150 |
SOC_DAPM_SINGLE("AUXI2HP Playback Switch", ALC5623_AUXIN_VOL, 15, 1, 1), |
| 151 |
SOC_DAPM_SINGLE("MIC12HP Playback Switch", ALC5623_MIC_ROUTING_CTRL, 15, 1, 1), |
| 152 |
SOC_DAPM_SINGLE("MIC22HP Playback Switch", ALC5623_MIC_ROUTING_CTRL, 7, 1, 1), |
| 153 |
SOC_DAPM_SINGLE("DAC2HP Playback Switch", ALC5623_STEREO_DAC_VOL, 15, 1, 1), |
| 154 |
}; |
| 155 |
|
| 156 |
static const struct snd_kcontrol_new alc5623_hpl_mixer_controls[] = { |
| 157 |
SOC_DAPM_SINGLE("ADC2HP_L Playback Switch", ALC5623_ADC_REC_GAIN, 15, 1, 1), |
| 158 |
}; |
| 159 |
|
| 160 |
static const struct snd_kcontrol_new alc5623_hpr_mixer_controls[] = { |
| 161 |
SOC_DAPM_SINGLE("ADC2HP_R Playback Switch", ALC5623_ADC_REC_GAIN, 14, 1, 1), |
| 162 |
}; |
| 163 |
|
| 164 |
static const struct snd_kcontrol_new alc5623_mono_mixer_controls[] = { |
| 165 |
SOC_DAPM_SINGLE("ADC2MONO_L Playback Switch", ALC5623_ADC_REC_GAIN, 13, 1, 1), |
| 166 |
SOC_DAPM_SINGLE("ADC2MONO_R Playback Switch", ALC5623_ADC_REC_GAIN, 12, 1, 1), |
| 167 |
SOC_DAPM_SINGLE("LI2MONO Playback Switch", ALC5623_LINE_IN_VOL, 13, 1, 1), |
| 168 |
SOC_DAPM_SINGLE("AUXI2MONO Playback Switch", ALC5623_AUXIN_VOL, 13, 1, 1), |
| 169 |
SOC_DAPM_SINGLE("MIC12MONO Playback Switch", ALC5623_MIC_ROUTING_CTRL, 13, 1, 1), |
| 170 |
SOC_DAPM_SINGLE("MIC22MONO Playback Switch", ALC5623_MIC_ROUTING_CTRL, 5, 1, 1), |
| 171 |
SOC_DAPM_SINGLE("DAC2MONO Playback Switch", ALC5623_STEREO_DAC_VOL, 13, 1, 1), |
| 172 |
}; |
| 173 |
|
| 174 |
static const struct snd_kcontrol_new alc5623_speaker_mixer_controls[] = { |
| 175 |
SOC_DAPM_SINGLE("LI2SPK Playback Switch", ALC5623_LINE_IN_VOL, 14, 1, 1), |
| 176 |
SOC_DAPM_SINGLE("AUXI2SPK Playback Switch", ALC5623_AUXIN_VOL, 14, 1, 1), |
| 177 |
SOC_DAPM_SINGLE("MIC12SPK Playback Switch", ALC5623_MIC_ROUTING_CTRL, 14, 1, 1), |
| 178 |
SOC_DAPM_SINGLE("MIC22SPK Playback Switch", ALC5623_MIC_ROUTING_CTRL, 6, 1, 1), |
| 179 |
SOC_DAPM_SINGLE("DAC2SPK Playback Switch", ALC5623_STEREO_DAC_VOL, 14, 1, 1), |
| 180 |
}; |
| 181 |
|
| 182 |
/* Left Record Mixer */ |
| 183 |
static const struct snd_kcontrol_new alc5623_captureL_mixer_controls[] = { |
| 184 |
SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5623_ADC_REC_MIXER, 14, 1, 1), |
| 185 |
SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5623_ADC_REC_MIXER, 13, 1, 1), |
| 186 |
SOC_DAPM_SINGLE("LineInL Capture Switch", ALC5623_ADC_REC_MIXER, 12, 1, 1), |
| 187 |
SOC_DAPM_SINGLE("Left AuxI Capture Switch", ALC5623_ADC_REC_MIXER, 11, 1, 1), |
| 188 |
SOC_DAPM_SINGLE("HPMixerL Capture Switch", ALC5623_ADC_REC_MIXER, 10, 1, 1), |
| 189 |
SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5623_ADC_REC_MIXER, 9, 1, 1), |
| 190 |
SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5623_ADC_REC_MIXER, 8, 1, 1), |
| 191 |
}; |
| 192 |
|
| 193 |
/* Right Record Mixer */ |
| 194 |
static const struct snd_kcontrol_new alc5623_captureR_mixer_controls[] = { |
| 195 |
SOC_DAPM_SINGLE("Mic1 Capture Switch", ALC5623_ADC_REC_MIXER, 6, 1, 1), |
| 196 |
SOC_DAPM_SINGLE("Mic2 Capture Switch", ALC5623_ADC_REC_MIXER, 5, 1, 1), |
| 197 |
SOC_DAPM_SINGLE("LineInR Capture Switch", ALC5623_ADC_REC_MIXER, 4, 1, 1), |
| 198 |
SOC_DAPM_SINGLE("Right AuxI Capture Switch", ALC5623_ADC_REC_MIXER, 3, 1, 1), |
| 199 |
SOC_DAPM_SINGLE("HPMixerR Capture Switch", ALC5623_ADC_REC_MIXER, 2, 1, 1), |
| 200 |
SOC_DAPM_SINGLE("SPKMixer Capture Switch", ALC5623_ADC_REC_MIXER, 1, 1, 1), |
| 201 |
SOC_DAPM_SINGLE("MonoMixer Capture Switch", ALC5623_ADC_REC_MIXER, 0, 1, 1), |
| 202 |
}; |
| 203 |
|
| 204 |
static const char *alc5623_spk_n_sour_sel[] = { |
| 205 |
"RN/-R", "RP/+R", "LN/-R", "Vmid" }; |
| 206 |
static const char *alc5623_hpl_out_input_sel[] = { |
| 207 |
"Vmid", "HP Left Mix"}; |
| 208 |
static const char *alc5623_hpr_out_input_sel[] = { |
| 209 |
"Vmid", "HP Right Mix"}; |
| 210 |
static const char *alc5623_spkout_input_sel[] = { |
| 211 |
"Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"}; |
| 212 |
static const char *alc5623_aux_out_input_sel[] = { |
| 213 |
"Vmid", "HPOut Mix", "Speaker Mix", "Mono Mix"}; |
| 214 |
|
| 215 |
/* auxout output mux */ |
| 216 |
static SOC_ENUM_SINGLE_DECL(alc5623_aux_out_input_enum, |
| 217 |
ALC5623_OUTPUT_MIXER_CTRL, 6, |
| 218 |
alc5623_aux_out_input_sel); |
| 219 |
static const struct snd_kcontrol_new alc5623_auxout_mux_controls = |
| 220 |
SOC_DAPM_ENUM("Route", alc5623_aux_out_input_enum); |
| 221 |
|
| 222 |
/* speaker output mux */ |
| 223 |
static SOC_ENUM_SINGLE_DECL(alc5623_spkout_input_enum, |
| 224 |
ALC5623_OUTPUT_MIXER_CTRL, 10, |
| 225 |
alc5623_spkout_input_sel); |
| 226 |
static const struct snd_kcontrol_new alc5623_spkout_mux_controls = |
| 227 |
SOC_DAPM_ENUM("Route", alc5623_spkout_input_enum); |
| 228 |
|
| 229 |
/* headphone left output mux */ |
| 230 |
static SOC_ENUM_SINGLE_DECL(alc5623_hpl_out_input_enum, |
| 231 |
ALC5623_OUTPUT_MIXER_CTRL, 9, |
| 232 |
alc5623_hpl_out_input_sel); |
| 233 |
static const struct snd_kcontrol_new alc5623_hpl_out_mux_controls = |
| 234 |
SOC_DAPM_ENUM("Route", alc5623_hpl_out_input_enum); |
| 235 |
|
| 236 |
/* headphone right output mux */ |
| 237 |
static SOC_ENUM_SINGLE_DECL(alc5623_hpr_out_input_enum, |
| 238 |
ALC5623_OUTPUT_MIXER_CTRL, 8, |
| 239 |
alc5623_hpr_out_input_sel); |
| 240 |
static const struct snd_kcontrol_new alc5623_hpr_out_mux_controls = |
| 241 |
SOC_DAPM_ENUM("Route", alc5623_hpr_out_input_enum); |
| 242 |
|
| 243 |
/* speaker output N select */ |
| 244 |
static SOC_ENUM_SINGLE_DECL(alc5623_spk_n_sour_enum, |
| 245 |
ALC5623_OUTPUT_MIXER_CTRL, 14, |
| 246 |
alc5623_spk_n_sour_sel); |
| 247 |
static const struct snd_kcontrol_new alc5623_spkoutn_mux_controls = |
| 248 |
SOC_DAPM_ENUM("Route", alc5623_spk_n_sour_enum); |
| 249 |
|
| 250 |
static const struct snd_soc_dapm_widget alc5623_dapm_widgets[] = { |
| 251 |
/* Muxes */ |
| 252 |
SND_SOC_DAPM_MUX("AuxOut Mux", SND_SOC_NOPM, 0, 0, |
| 253 |
&alc5623_auxout_mux_controls), |
| 254 |
SND_SOC_DAPM_MUX("SpeakerOut Mux", SND_SOC_NOPM, 0, 0, |
| 255 |
&alc5623_spkout_mux_controls), |
| 256 |
SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, |
| 257 |
&alc5623_hpl_out_mux_controls), |
| 258 |
SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, |
| 259 |
&alc5623_hpr_out_mux_controls), |
| 260 |
SND_SOC_DAPM_MUX("SpeakerOut N Mux", SND_SOC_NOPM, 0, 0, |
| 261 |
&alc5623_spkoutn_mux_controls), |
| 262 |
|
| 263 |
/* output mixers */ |
| 264 |
SND_SOC_DAPM_MIXER("HP Mix", SND_SOC_NOPM, 0, 0, |
| 265 |
&alc5623_hp_mixer_controls[0], |
| 266 |
ARRAY_SIZE(alc5623_hp_mixer_controls)), |
| 267 |
SND_SOC_DAPM_MIXER("HPR Mix", ALC5623_PWR_MANAG_ADD2, 4, 0, |
| 268 |
&alc5623_hpr_mixer_controls[0], |
| 269 |
ARRAY_SIZE(alc5623_hpr_mixer_controls)), |
| 270 |
SND_SOC_DAPM_MIXER("HPL Mix", ALC5623_PWR_MANAG_ADD2, 5, 0, |
| 271 |
&alc5623_hpl_mixer_controls[0], |
| 272 |
ARRAY_SIZE(alc5623_hpl_mixer_controls)), |
| 273 |
SND_SOC_DAPM_MIXER("HPOut Mix", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 274 |
SND_SOC_DAPM_MIXER("Mono Mix", ALC5623_PWR_MANAG_ADD2, 2, 0, |
| 275 |
&alc5623_mono_mixer_controls[0], |
| 276 |
ARRAY_SIZE(alc5623_mono_mixer_controls)), |
| 277 |
SND_SOC_DAPM_MIXER("Speaker Mix", ALC5623_PWR_MANAG_ADD2, 3, 0, |
| 278 |
&alc5623_speaker_mixer_controls[0], |
| 279 |
ARRAY_SIZE(alc5623_speaker_mixer_controls)), |
| 280 |
|
| 281 |
/* input mixers */ |
| 282 |
SND_SOC_DAPM_MIXER("Left Capture Mix", ALC5623_PWR_MANAG_ADD2, 1, 0, |
| 283 |
&alc5623_captureL_mixer_controls[0], |
| 284 |
ARRAY_SIZE(alc5623_captureL_mixer_controls)), |
| 285 |
SND_SOC_DAPM_MIXER("Right Capture Mix", ALC5623_PWR_MANAG_ADD2, 0, 0, |
| 286 |
&alc5623_captureR_mixer_controls[0], |
| 287 |
ARRAY_SIZE(alc5623_captureR_mixer_controls)), |
| 288 |
|
| 289 |
SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", |
| 290 |
ALC5623_PWR_MANAG_ADD2, 9, 0), |
| 291 |
SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", |
| 292 |
ALC5623_PWR_MANAG_ADD2, 8, 0), |
| 293 |
SND_SOC_DAPM_MIXER("I2S Mix", ALC5623_PWR_MANAG_ADD1, 15, 0, NULL, 0), |
| 294 |
SND_SOC_DAPM_MIXER("AuxI Mix", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 295 |
SND_SOC_DAPM_MIXER("Line Mix", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 296 |
SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", |
| 297 |
ALC5623_PWR_MANAG_ADD2, 7, 0), |
| 298 |
SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", |
| 299 |
ALC5623_PWR_MANAG_ADD2, 6, 0), |
| 300 |
SND_SOC_DAPM_PGA("Left Headphone", ALC5623_PWR_MANAG_ADD3, 10, 0, NULL, 0), |
| 301 |
SND_SOC_DAPM_PGA("Right Headphone", ALC5623_PWR_MANAG_ADD3, 9, 0, NULL, 0), |
| 302 |
SND_SOC_DAPM_PGA("SpeakerOut", ALC5623_PWR_MANAG_ADD3, 12, 0, NULL, 0), |
| 303 |
SND_SOC_DAPM_PGA("Left AuxOut", ALC5623_PWR_MANAG_ADD3, 14, 0, NULL, 0), |
| 304 |
SND_SOC_DAPM_PGA("Right AuxOut", ALC5623_PWR_MANAG_ADD3, 13, 0, NULL, 0), |
| 305 |
SND_SOC_DAPM_PGA("Left LineIn", ALC5623_PWR_MANAG_ADD3, 7, 0, NULL, 0), |
| 306 |
SND_SOC_DAPM_PGA("Right LineIn", ALC5623_PWR_MANAG_ADD3, 6, 0, NULL, 0), |
| 307 |
SND_SOC_DAPM_PGA("Left AuxI", ALC5623_PWR_MANAG_ADD3, 5, 0, NULL, 0), |
| 308 |
SND_SOC_DAPM_PGA("Right AuxI", ALC5623_PWR_MANAG_ADD3, 4, 0, NULL, 0), |
| 309 |
SND_SOC_DAPM_PGA("MIC1 PGA", ALC5623_PWR_MANAG_ADD3, 3, 0, NULL, 0), |
| 310 |
SND_SOC_DAPM_PGA("MIC2 PGA", ALC5623_PWR_MANAG_ADD3, 2, 0, NULL, 0), |
| 311 |
SND_SOC_DAPM_PGA("MIC1 Pre Amp", ALC5623_PWR_MANAG_ADD3, 1, 0, NULL, 0), |
| 312 |
SND_SOC_DAPM_PGA("MIC2 Pre Amp", ALC5623_PWR_MANAG_ADD3, 0, 0, NULL, 0), |
| 313 |
SND_SOC_DAPM_MICBIAS("Mic Bias1", ALC5623_PWR_MANAG_ADD1, 11, 0), |
| 314 |
|
| 315 |
SND_SOC_DAPM_OUTPUT("AUXOUTL"), |
| 316 |
SND_SOC_DAPM_OUTPUT("AUXOUTR"), |
| 317 |
SND_SOC_DAPM_OUTPUT("HPL"), |
| 318 |
SND_SOC_DAPM_OUTPUT("HPR"), |
| 319 |
SND_SOC_DAPM_OUTPUT("SPKOUT"), |
| 320 |
SND_SOC_DAPM_OUTPUT("SPKOUTN"), |
| 321 |
SND_SOC_DAPM_INPUT("LINEINL"), |
| 322 |
SND_SOC_DAPM_INPUT("LINEINR"), |
| 323 |
SND_SOC_DAPM_INPUT("AUXINL"), |
| 324 |
SND_SOC_DAPM_INPUT("AUXINR"), |
| 325 |
SND_SOC_DAPM_INPUT("MIC1"), |
| 326 |
SND_SOC_DAPM_INPUT("MIC2"), |
| 327 |
SND_SOC_DAPM_VMID("Vmid"), |
| 328 |
}; |
| 329 |
|
| 330 |
static const char *alc5623_amp_names[] = {"AB Amp", "D Amp"}; |
| 331 |
static SOC_ENUM_SINGLE_DECL(alc5623_amp_enum, |
| 332 |
ALC5623_OUTPUT_MIXER_CTRL, 13, |
| 333 |
alc5623_amp_names); |
| 334 |
static const struct snd_kcontrol_new alc5623_amp_mux_controls = |
| 335 |
SOC_DAPM_ENUM("Route", alc5623_amp_enum); |
| 336 |
|
| 337 |
static const struct snd_soc_dapm_widget alc5623_dapm_amp_widgets[] = { |
| 338 |
SND_SOC_DAPM_PGA_E("D Amp", ALC5623_PWR_MANAG_ADD2, 14, 0, NULL, 0, |
| 339 |
amp_mixer_event, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), |
| 340 |
SND_SOC_DAPM_PGA("AB Amp", ALC5623_PWR_MANAG_ADD2, 15, 0, NULL, 0), |
| 341 |
SND_SOC_DAPM_MUX("AB-D Amp Mux", SND_SOC_NOPM, 0, 0, |
| 342 |
&alc5623_amp_mux_controls), |
| 343 |
}; |
| 344 |
|
| 345 |
static const struct snd_soc_dapm_route intercon[] = { |
| 346 |
/* virtual mixer - mixes left & right channels */ |
| 347 |
{"I2S Mix", NULL, "Left DAC"}, |
| 348 |
{"I2S Mix", NULL, "Right DAC"}, |
| 349 |
{"Line Mix", NULL, "Right LineIn"}, |
| 350 |
{"Line Mix", NULL, "Left LineIn"}, |
| 351 |
{"AuxI Mix", NULL, "Left AuxI"}, |
| 352 |
{"AuxI Mix", NULL, "Right AuxI"}, |
| 353 |
{"AUXOUTL", NULL, "Left AuxOut"}, |
| 354 |
{"AUXOUTR", NULL, "Right AuxOut"}, |
| 355 |
|
| 356 |
/* HP mixer */ |
| 357 |
{"HPL Mix", "ADC2HP_L Playback Switch", "Left Capture Mix"}, |
| 358 |
{"HPL Mix", NULL, "HP Mix"}, |
| 359 |
{"HPR Mix", "ADC2HP_R Playback Switch", "Right Capture Mix"}, |
| 360 |
{"HPR Mix", NULL, "HP Mix"}, |
| 361 |
{"HP Mix", "LI2HP Playback Switch", "Line Mix"}, |
| 362 |
{"HP Mix", "AUXI2HP Playback Switch", "AuxI Mix"}, |
| 363 |
{"HP Mix", "MIC12HP Playback Switch", "MIC1 PGA"}, |
| 364 |
{"HP Mix", "MIC22HP Playback Switch", "MIC2 PGA"}, |
| 365 |
{"HP Mix", "DAC2HP Playback Switch", "I2S Mix"}, |
| 366 |
|
| 367 |
/* speaker mixer */ |
| 368 |
{"Speaker Mix", "LI2SPK Playback Switch", "Line Mix"}, |
| 369 |
{"Speaker Mix", "AUXI2SPK Playback Switch", "AuxI Mix"}, |
| 370 |
{"Speaker Mix", "MIC12SPK Playback Switch", "MIC1 PGA"}, |
| 371 |
{"Speaker Mix", "MIC22SPK Playback Switch", "MIC2 PGA"}, |
| 372 |
{"Speaker Mix", "DAC2SPK Playback Switch", "I2S Mix"}, |
| 373 |
|
| 374 |
/* mono mixer */ |
| 375 |
{"Mono Mix", "ADC2MONO_L Playback Switch", "Left Capture Mix"}, |
| 376 |
{"Mono Mix", "ADC2MONO_R Playback Switch", "Right Capture Mix"}, |
| 377 |
{"Mono Mix", "LI2MONO Playback Switch", "Line Mix"}, |
| 378 |
{"Mono Mix", "AUXI2MONO Playback Switch", "AuxI Mix"}, |
| 379 |
{"Mono Mix", "MIC12MONO Playback Switch", "MIC1 PGA"}, |
| 380 |
{"Mono Mix", "MIC22MONO Playback Switch", "MIC2 PGA"}, |
| 381 |
{"Mono Mix", "DAC2MONO Playback Switch", "I2S Mix"}, |
| 382 |
|
| 383 |
/* Left record mixer */ |
| 384 |
{"Left Capture Mix", "LineInL Capture Switch", "LINEINL"}, |
| 385 |
{"Left Capture Mix", "Left AuxI Capture Switch", "AUXINL"}, |
| 386 |
{"Left Capture Mix", "Mic1 Capture Switch", "MIC1 Pre Amp"}, |
| 387 |
{"Left Capture Mix", "Mic2 Capture Switch", "MIC2 Pre Amp"}, |
| 388 |
{"Left Capture Mix", "HPMixerL Capture Switch", "HPL Mix"}, |
| 389 |
{"Left Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"}, |
| 390 |
{"Left Capture Mix", "MonoMixer Capture Switch", "Mono Mix"}, |
| 391 |
|
| 392 |
/*Right record mixer */ |
| 393 |
{"Right Capture Mix", "LineInR Capture Switch", "LINEINR"}, |
| 394 |
{"Right Capture Mix", "Right AuxI Capture Switch", "AUXINR"}, |
| 395 |
{"Right Capture Mix", "Mic1 Capture Switch", "MIC1 Pre Amp"}, |
| 396 |
{"Right Capture Mix", "Mic2 Capture Switch", "MIC2 Pre Amp"}, |
| 397 |
{"Right Capture Mix", "HPMixerR Capture Switch", "HPR Mix"}, |
| 398 |
{"Right Capture Mix", "SPKMixer Capture Switch", "Speaker Mix"}, |
| 399 |
{"Right Capture Mix", "MonoMixer Capture Switch", "Mono Mix"}, |
| 400 |
|
| 401 |
/* headphone left mux */ |
| 402 |
{"Left Headphone Mux", "HP Left Mix", "HPL Mix"}, |
| 403 |
{"Left Headphone Mux", "Vmid", "Vmid"}, |
| 404 |
|
| 405 |
/* headphone right mux */ |
| 406 |
{"Right Headphone Mux", "HP Right Mix", "HPR Mix"}, |
| 407 |
{"Right Headphone Mux", "Vmid", "Vmid"}, |
| 408 |
|
| 409 |
/* speaker out mux */ |
| 410 |
{"SpeakerOut Mux", "Vmid", "Vmid"}, |
| 411 |
{"SpeakerOut Mux", "HPOut Mix", "HPOut Mix"}, |
| 412 |
{"SpeakerOut Mux", "Speaker Mix", "Speaker Mix"}, |
| 413 |
{"SpeakerOut Mux", "Mono Mix", "Mono Mix"}, |
| 414 |
|
| 415 |
/* Mono/Aux Out mux */ |
| 416 |
{"AuxOut Mux", "Vmid", "Vmid"}, |
| 417 |
{"AuxOut Mux", "HPOut Mix", "HPOut Mix"}, |
| 418 |
{"AuxOut Mux", "Speaker Mix", "Speaker Mix"}, |
| 419 |
{"AuxOut Mux", "Mono Mix", "Mono Mix"}, |
| 420 |
|
| 421 |
/* output pga */ |
| 422 |
{"HPL", NULL, "Left Headphone"}, |
| 423 |
{"Left Headphone", NULL, "Left Headphone Mux"}, |
| 424 |
{"HPR", NULL, "Right Headphone"}, |
| 425 |
{"Right Headphone", NULL, "Right Headphone Mux"}, |
| 426 |
{"Left AuxOut", NULL, "AuxOut Mux"}, |
| 427 |
{"Right AuxOut", NULL, "AuxOut Mux"}, |
| 428 |
|
| 429 |
/* input pga */ |
| 430 |
{"Left LineIn", NULL, "LINEINL"}, |
| 431 |
{"Right LineIn", NULL, "LINEINR"}, |
| 432 |
{"Left AuxI", NULL, "AUXINL"}, |
| 433 |
{"Right AuxI", NULL, "AUXINR"}, |
| 434 |
{"MIC1 Pre Amp", NULL, "MIC1"}, |
| 435 |
{"MIC2 Pre Amp", NULL, "MIC2"}, |
| 436 |
{"MIC1 PGA", NULL, "MIC1 Pre Amp"}, |
| 437 |
{"MIC2 PGA", NULL, "MIC2 Pre Amp"}, |
| 438 |
|
| 439 |
/* left ADC */ |
| 440 |
{"Left ADC", NULL, "Left Capture Mix"}, |
| 441 |
|
| 442 |
/* right ADC */ |
| 443 |
{"Right ADC", NULL, "Right Capture Mix"}, |
| 444 |
|
| 445 |
{"SpeakerOut N Mux", "RN/-R", "SpeakerOut"}, |
| 446 |
{"SpeakerOut N Mux", "RP/+R", "SpeakerOut"}, |
| 447 |
{"SpeakerOut N Mux", "LN/-R", "SpeakerOut"}, |
| 448 |
{"SpeakerOut N Mux", "Vmid", "Vmid"}, |
| 449 |
|
| 450 |
{"SPKOUT", NULL, "SpeakerOut"}, |
| 451 |
{"SPKOUTN", NULL, "SpeakerOut N Mux"}, |
| 452 |
}; |
| 453 |
|
| 454 |
static const struct snd_soc_dapm_route intercon_spk[] = { |
| 455 |
{"SpeakerOut", NULL, "SpeakerOut Mux"}, |
| 456 |
}; |
| 457 |
|
| 458 |
static const struct snd_soc_dapm_route intercon_amp_spk[] = { |
| 459 |
{"AB Amp", NULL, "SpeakerOut Mux"}, |
| 460 |
{"D Amp", NULL, "SpeakerOut Mux"}, |
| 461 |
{"AB-D Amp Mux", "AB Amp", "AB Amp"}, |
| 462 |
{"AB-D Amp Mux", "D Amp", "D Amp"}, |
| 463 |
{"SpeakerOut", NULL, "AB-D Amp Mux"}, |
| 464 |
}; |
| 465 |
|
| 466 |
/* PLL divisors */ |
| 467 |
struct _pll_div { |
| 468 |
u32 pll_in; |
| 469 |
u32 pll_out; |
| 470 |
u16 regvalue; |
| 471 |
}; |
| 472 |
|
| 473 |
/* Note : pll code from original alc5623 driver. Not sure of how good it is */ |
| 474 |
/* useful only for master mode */ |
| 475 |
static const struct _pll_div codec_master_pll_div[] = { |
| 476 |
|
| 477 |
{ 2048000, 8192000, 0x0ea0}, |
| 478 |
{ 3686400, 8192000, 0x4e27}, |
| 479 |
{ 12000000, 8192000, 0x456b}, |
| 480 |
{ 13000000, 8192000, 0x495f}, |
| 481 |
{ 13100000, 8192000, 0x0320}, |
| 482 |
{ 2048000, 11289600, 0xf637}, |
| 483 |
{ 3686400, 11289600, 0x2f22}, |
| 484 |
{ 12000000, 11289600, 0x3e2f}, |
| 485 |
{ 13000000, 11289600, 0x4d5b}, |
| 486 |
{ 13100000, 11289600, 0x363b}, |
| 487 |
{ 2048000, 16384000, 0x1ea0}, |
| 488 |
{ 3686400, 16384000, 0x9e27}, |
| 489 |
{ 12000000, 16384000, 0x452b}, |
| 490 |
{ 13000000, 16384000, 0x542f}, |
| 491 |
{ 13100000, 16384000, 0x03a0}, |
| 492 |
{ 2048000, 16934400, 0xe625}, |
| 493 |
{ 3686400, 16934400, 0x9126}, |
| 494 |
{ 12000000, 16934400, 0x4d2c}, |
| 495 |
{ 13000000, 16934400, 0x742f}, |
| 496 |
{ 13100000, 16934400, 0x3c27}, |
| 497 |
{ 2048000, 22579200, 0x2aa0}, |
| 498 |
{ 3686400, 22579200, 0x2f20}, |
| 499 |
{ 12000000, 22579200, 0x7e2f}, |
| 500 |
{ 13000000, 22579200, 0x742f}, |
| 501 |
{ 13100000, 22579200, 0x3c27}, |
| 502 |
{ 2048000, 24576000, 0x2ea0}, |
| 503 |
{ 3686400, 24576000, 0xee27}, |
| 504 |
{ 12000000, 24576000, 0x2915}, |
| 505 |
{ 13000000, 24576000, 0x772e}, |
| 506 |
{ 13100000, 24576000, 0x0d20}, |
| 507 |
}; |
| 508 |
|
| 509 |
static const struct _pll_div codec_slave_pll_div[] = { |
| 510 |
|
| 511 |
{ 1024000, 16384000, 0x3ea0}, |
| 512 |
{ 1411200, 22579200, 0x3ea0}, |
| 513 |
{ 1536000, 24576000, 0x3ea0}, |
| 514 |
{ 2048000, 16384000, 0x1ea0}, |
| 515 |
{ 2822400, 22579200, 0x1ea0}, |
| 516 |
{ 3072000, 24576000, 0x1ea0}, |
| 517 |
|
| 518 |
}; |
| 519 |
|
| 520 |
static int alc5623_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, |
| 521 |
int source, unsigned int freq_in, unsigned int freq_out) |
| 522 |
{ |
| 523 |
int i; |
| 524 |
struct snd_soc_component *component = codec_dai->component; |
| 525 |
int gbl_clk = 0, pll_div = 0; |
| 526 |
u16 reg; |
| 527 |
|
| 528 |
if (pll_id < ALC5623_PLL_FR_MCLK || pll_id > ALC5623_PLL_FR_BCK) |
| 529 |
return -ENODEV; |
| 530 |
|
| 531 |
/* Disable PLL power */ |
| 532 |
snd_soc_component_update_bits(component, ALC5623_PWR_MANAG_ADD2, |
| 533 |
ALC5623_PWR_ADD2_PLL, |
| 534 |
0); |
| 535 |
|
| 536 |
/* pll is not used in slave mode */ |
| 537 |
reg = snd_soc_component_read(component, ALC5623_DAI_CONTROL); |
| 538 |
if (reg & ALC5623_DAI_SDP_SLAVE_MODE) |
| 539 |
return 0; |
| 540 |
|
| 541 |
if (!freq_in || !freq_out) |
| 542 |
return 0; |
| 543 |
|
| 544 |
switch (pll_id) { |
| 545 |
case ALC5623_PLL_FR_MCLK: |
| 546 |
for (i = 0; i < ARRAY_SIZE(codec_master_pll_div); i++) { |
| 547 |
if (codec_master_pll_div[i].pll_in == freq_in |
| 548 |
&& codec_master_pll_div[i].pll_out == freq_out) { |
| 549 |
/* PLL source from MCLK */ |
| 550 |
pll_div = codec_master_pll_div[i].regvalue; |
| 551 |
break; |
| 552 |
} |
| 553 |
} |
| 554 |
break; |
| 555 |
case ALC5623_PLL_FR_BCK: |
| 556 |
for (i = 0; i < ARRAY_SIZE(codec_slave_pll_div); i++) { |
| 557 |
if (codec_slave_pll_div[i].pll_in == freq_in |
| 558 |
&& codec_slave_pll_div[i].pll_out == freq_out) { |
| 559 |
/* PLL source from Bitclk */ |
| 560 |
gbl_clk = ALC5623_GBL_CLK_PLL_SOUR_SEL_BITCLK; |
| 561 |
pll_div = codec_slave_pll_div[i].regvalue; |
| 562 |
break; |
| 563 |
} |
| 564 |
} |
| 565 |
break; |
| 566 |
default: |
| 567 |
return -EINVAL; |
| 568 |
} |
| 569 |
|
| 570 |
if (!pll_div) |
| 571 |
return -EINVAL; |
| 572 |
|
| 573 |
snd_soc_component_write(component, ALC5623_GLOBAL_CLK_CTRL_REG, gbl_clk); |
| 574 |
snd_soc_component_write(component, ALC5623_PLL_CTRL, pll_div); |
| 575 |
snd_soc_component_update_bits(component, ALC5623_PWR_MANAG_ADD2, |
| 576 |
ALC5623_PWR_ADD2_PLL, |
| 577 |
ALC5623_PWR_ADD2_PLL); |
| 578 |
gbl_clk |= ALC5623_GBL_CLK_SYS_SOUR_SEL_PLL; |
| 579 |
snd_soc_component_write(component, ALC5623_GLOBAL_CLK_CTRL_REG, gbl_clk); |
| 580 |
|
| 581 |
return 0; |
| 582 |
} |
| 583 |
|
| 584 |
struct _coeff_div { |
| 585 |
u16 fs; |
| 586 |
u16 regvalue; |
| 587 |
}; |
| 588 |
|
| 589 |
/* codec hifi mclk (after PLL) clock divider coefficients */ |
| 590 |
/* values inspired from column BCLK=32Fs of Appendix A table */ |
| 591 |
static const struct _coeff_div coeff_div[] = { |
| 592 |
{256*8, 0x3a69}, |
| 593 |
{384*8, 0x3c6b}, |
| 594 |
{256*4, 0x2a69}, |
| 595 |
{384*4, 0x2c6b}, |
| 596 |
{256*2, 0x1a69}, |
| 597 |
{384*2, 0x1c6b}, |
| 598 |
{256*1, 0x0a69}, |
| 599 |
{384*1, 0x0c6b}, |
| 600 |
}; |
| 601 |
|
| 602 |
static int get_coeff(struct snd_soc_component *component, int rate) |
| 603 |
{ |
| 604 |
struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component); |
| 605 |
int i; |
| 606 |
|
| 607 |
for (i = 0; i < ARRAY_SIZE(coeff_div); i++) { |
| 608 |
if (coeff_div[i].fs * rate == alc5623->sysclk) |
| 609 |
return i; |
| 610 |
} |
| 611 |
return -EINVAL; |
| 612 |
} |
| 613 |
|
| 614 |
/* |
| 615 |
* Clock after PLL and dividers |
| 616 |
*/ |
| 617 |
static int alc5623_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 618 |
int clk_id, unsigned int freq, int dir) |
| 619 |
{ |
| 620 |
struct snd_soc_component *component = codec_dai->component; |
| 621 |
struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component); |
| 622 |
|
| 623 |
switch (freq) { |
| 624 |
case 8192000: |
| 625 |
case 11289600: |
| 626 |
case 12288000: |
| 627 |
case 16384000: |
| 628 |
case 16934400: |
| 629 |
case 18432000: |
| 630 |
case 22579200: |
| 631 |
case 24576000: |
| 632 |
alc5623->sysclk = freq; |
| 633 |
return 0; |
| 634 |
} |
| 635 |
return -EINVAL; |
| 636 |
} |
| 637 |
|
| 638 |
static int alc5623_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 639 |
unsigned int fmt) |
| 640 |
{ |
| 641 |
struct snd_soc_component *component = codec_dai->component; |
| 642 |
u16 iface = 0; |
| 643 |
|
| 644 |
/* set audio interface clocking */ |
| 645 |
switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) { |
| 646 |
case SND_SOC_DAIFMT_CBP_CFP: |
| 647 |
iface = ALC5623_DAI_SDP_MASTER_MODE; |
| 648 |
break; |
| 649 |
case SND_SOC_DAIFMT_CBC_CFC: |
| 650 |
iface = ALC5623_DAI_SDP_SLAVE_MODE; |
| 651 |
break; |
| 652 |
default: |
| 653 |
return -EINVAL; |
| 654 |
} |
| 655 |
|
| 656 |
/* interface format */ |
| 657 |
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 658 |
case SND_SOC_DAIFMT_I2S: |
| 659 |
iface |= ALC5623_DAI_I2S_DF_I2S; |
| 660 |
break; |
| 661 |
case SND_SOC_DAIFMT_RIGHT_J: |
| 662 |
iface |= ALC5623_DAI_I2S_DF_RIGHT; |
| 663 |
break; |
| 664 |
case SND_SOC_DAIFMT_LEFT_J: |
| 665 |
iface |= ALC5623_DAI_I2S_DF_LEFT; |
| 666 |
break; |
| 667 |
case SND_SOC_DAIFMT_DSP_A: |
| 668 |
iface |= ALC5623_DAI_I2S_DF_PCM; |
| 669 |
break; |
| 670 |
case SND_SOC_DAIFMT_DSP_B: |
| 671 |
iface |= ALC5623_DAI_I2S_DF_PCM | ALC5623_DAI_I2S_PCM_MODE; |
| 672 |
break; |
| 673 |
default: |
| 674 |
return -EINVAL; |
| 675 |
} |
| 676 |
|
| 677 |
/* clock inversion */ |
| 678 |
switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 679 |
case SND_SOC_DAIFMT_NB_NF: |
| 680 |
break; |
| 681 |
case SND_SOC_DAIFMT_IB_NF: |
| 682 |
iface |= ALC5623_DAI_MAIN_I2S_BCLK_POL_CTRL; |
| 683 |
break; |
| 684 |
default: |
| 685 |
return -EINVAL; |
| 686 |
} |
| 687 |
|
| 688 |
return snd_soc_component_write(component, ALC5623_DAI_CONTROL, iface); |
| 689 |
} |
| 690 |
|
| 691 |
static int alc5623_pcm_hw_params(struct snd_pcm_substream *substream, |
| 692 |
struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) |
| 693 |
{ |
| 694 |
struct snd_soc_component *component = dai->component; |
| 695 |
struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component); |
| 696 |
int coeff, rate; |
| 697 |
u16 iface; |
| 698 |
|
| 699 |
iface = snd_soc_component_read(component, ALC5623_DAI_CONTROL); |
| 700 |
iface &= ~ALC5623_DAI_I2S_DL_MASK; |
| 701 |
|
| 702 |
/* bit size */ |
| 703 |
switch (params_width(params)) { |
| 704 |
case 16: |
| 705 |
iface |= ALC5623_DAI_I2S_DL_16; |
| 706 |
break; |
| 707 |
case 20: |
| 708 |
iface |= ALC5623_DAI_I2S_DL_20; |
| 709 |
break; |
| 710 |
case 24: |
| 711 |
iface |= ALC5623_DAI_I2S_DL_24; |
| 712 |
break; |
| 713 |
case 32: |
| 714 |
iface |= ALC5623_DAI_I2S_DL_32; |
| 715 |
break; |
| 716 |
default: |
| 717 |
return -EINVAL; |
| 718 |
} |
| 719 |
|
| 720 |
/* set iface & srate */ |
| 721 |
snd_soc_component_write(component, ALC5623_DAI_CONTROL, iface); |
| 722 |
rate = params_rate(params); |
| 723 |
coeff = get_coeff(component, rate); |
| 724 |
if (coeff < 0) |
| 725 |
return -EINVAL; |
| 726 |
|
| 727 |
coeff = coeff_div[coeff].regvalue; |
| 728 |
dev_dbg(component->dev, "%s: sysclk=%d,rate=%d,coeff=0x%04x\n", |
| 729 |
__func__, alc5623->sysclk, rate, coeff); |
| 730 |
snd_soc_component_write(component, ALC5623_STEREO_AD_DA_CLK_CTRL, coeff); |
| 731 |
|
| 732 |
return 0; |
| 733 |
} |
| 734 |
|
| 735 |
static int alc5623_mute(struct snd_soc_dai *dai, int mute, int direction) |
| 736 |
{ |
| 737 |
struct snd_soc_component *component = dai->component; |
| 738 |
u16 hp_mute = ALC5623_MISC_M_DAC_L_INPUT | ALC5623_MISC_M_DAC_R_INPUT; |
| 739 |
u16 mute_reg = snd_soc_component_read(component, ALC5623_MISC_CTRL) & ~hp_mute; |
| 740 |
|
| 741 |
if (mute) |
| 742 |
mute_reg |= hp_mute; |
| 743 |
|
| 744 |
return snd_soc_component_write(component, ALC5623_MISC_CTRL, mute_reg); |
| 745 |
} |
| 746 |
|
| 747 |
#define ALC5623_ADD2_POWER_EN (ALC5623_PWR_ADD2_VREF \ |
| 748 |
| ALC5623_PWR_ADD2_DAC_REF_CIR) |
| 749 |
|
| 750 |
#define ALC5623_ADD3_POWER_EN (ALC5623_PWR_ADD3_MAIN_BIAS \ |
| 751 |
| ALC5623_PWR_ADD3_MIC1_BOOST_AD) |
| 752 |
|
| 753 |
#define ALC5623_ADD1_POWER_EN \ |
| 754 |
(ALC5623_PWR_ADD1_SHORT_CURR_DET_EN | ALC5623_PWR_ADD1_SOFTGEN_EN \ |
| 755 |
| ALC5623_PWR_ADD1_DEPOP_BUF_HP | ALC5623_PWR_ADD1_HP_OUT_AMP \ |
| 756 |
| ALC5623_PWR_ADD1_HP_OUT_ENH_AMP) |
| 757 |
|
| 758 |
#define ALC5623_ADD1_POWER_EN_5622 \ |
| 759 |
(ALC5623_PWR_ADD1_SHORT_CURR_DET_EN \ |
| 760 |
| ALC5623_PWR_ADD1_HP_OUT_AMP) |
| 761 |
|
| 762 |
static void enable_power_depop(struct snd_soc_component *component) |
| 763 |
{ |
| 764 |
struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component); |
| 765 |
|
| 766 |
snd_soc_component_update_bits(component, ALC5623_PWR_MANAG_ADD1, |
| 767 |
ALC5623_PWR_ADD1_SOFTGEN_EN, |
| 768 |
ALC5623_PWR_ADD1_SOFTGEN_EN); |
| 769 |
|
| 770 |
snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD3, ALC5623_ADD3_POWER_EN); |
| 771 |
|
| 772 |
snd_soc_component_update_bits(component, ALC5623_MISC_CTRL, |
| 773 |
ALC5623_MISC_HP_DEPOP_MODE2_EN, |
| 774 |
ALC5623_MISC_HP_DEPOP_MODE2_EN); |
| 775 |
|
| 776 |
msleep(500); |
| 777 |
|
| 778 |
snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD2, ALC5623_ADD2_POWER_EN); |
| 779 |
|
| 780 |
/* avoid writing '1' into 5622 reserved bits */ |
| 781 |
if (alc5623->id == 0x22) |
| 782 |
snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD1, |
| 783 |
ALC5623_ADD1_POWER_EN_5622); |
| 784 |
else |
| 785 |
snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD1, |
| 786 |
ALC5623_ADD1_POWER_EN); |
| 787 |
|
| 788 |
/* disable HP Depop2 */ |
| 789 |
snd_soc_component_update_bits(component, ALC5623_MISC_CTRL, |
| 790 |
ALC5623_MISC_HP_DEPOP_MODE2_EN, |
| 791 |
0); |
| 792 |
|
| 793 |
} |
| 794 |
|
| 795 |
static int alc5623_set_bias_level(struct snd_soc_component *component, |
| 796 |
enum snd_soc_bias_level level) |
| 797 |
{ |
| 798 |
switch (level) { |
| 799 |
case SND_SOC_BIAS_ON: |
| 800 |
enable_power_depop(component); |
| 801 |
break; |
| 802 |
case SND_SOC_BIAS_PREPARE: |
| 803 |
break; |
| 804 |
case SND_SOC_BIAS_STANDBY: |
| 805 |
/* everything off except vref/vmid, */ |
| 806 |
snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD2, |
| 807 |
ALC5623_PWR_ADD2_VREF); |
| 808 |
snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD3, |
| 809 |
ALC5623_PWR_ADD3_MAIN_BIAS); |
| 810 |
break; |
| 811 |
case SND_SOC_BIAS_OFF: |
| 812 |
/* everything off, dac mute, inactive */ |
| 813 |
snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD2, 0); |
| 814 |
snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD3, 0); |
| 815 |
snd_soc_component_write(component, ALC5623_PWR_MANAG_ADD1, 0); |
| 816 |
break; |
| 817 |
} |
| 818 |
return 0; |
| 819 |
} |
| 820 |
|
| 821 |
#define ALC5623_FORMATS (SNDRV_PCM_FMTBIT_S16_LE \ |
| 822 |
| SNDRV_PCM_FMTBIT_S24_LE \ |
| 823 |
| SNDRV_PCM_FMTBIT_S32_LE) |
| 824 |
|
| 825 |
static const struct snd_soc_dai_ops alc5623_dai_ops = { |
| 826 |
.hw_params = alc5623_pcm_hw_params, |
| 827 |
.mute_stream = alc5623_mute, |
| 828 |
.set_fmt = alc5623_set_dai_fmt, |
| 829 |
.set_sysclk = alc5623_set_dai_sysclk, |
| 830 |
.set_pll = alc5623_set_dai_pll, |
| 831 |
.no_capture_mute = 1, |
| 832 |
}; |
| 833 |
|
| 834 |
static struct snd_soc_dai_driver alc5623_dai = { |
| 835 |
.name = "alc5623-hifi", |
| 836 |
.playback = { |
| 837 |
.stream_name = "Playback", |
| 838 |
.channels_min = 1, |
| 839 |
.channels_max = 2, |
| 840 |
.rate_min = 8000, |
| 841 |
.rate_max = 48000, |
| 842 |
.rates = SNDRV_PCM_RATE_8000_48000, |
| 843 |
.formats = ALC5623_FORMATS,}, |
| 844 |
.capture = { |
| 845 |
.stream_name = "Capture", |
| 846 |
.channels_min = 1, |
| 847 |
.channels_max = 2, |
| 848 |
.rate_min = 8000, |
| 849 |
.rate_max = 48000, |
| 850 |
.rates = SNDRV_PCM_RATE_8000_48000, |
| 851 |
.formats = ALC5623_FORMATS,}, |
| 852 |
|
| 853 |
.ops = &alc5623_dai_ops, |
| 854 |
}; |
| 855 |
|
| 856 |
static int alc5623_suspend(struct snd_soc_component *component) |
| 857 |
{ |
| 858 |
struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component); |
| 859 |
|
| 860 |
regcache_cache_only(alc5623->regmap, true); |
| 861 |
|
| 862 |
return 0; |
| 863 |
} |
| 864 |
|
| 865 |
static int alc5623_resume(struct snd_soc_component *component) |
| 866 |
{ |
| 867 |
struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component); |
| 868 |
int ret; |
| 869 |
|
| 870 |
/* Sync reg_cache with the hardware */ |
| 871 |
regcache_cache_only(alc5623->regmap, false); |
| 872 |
ret = regcache_sync(alc5623->regmap); |
| 873 |
if (ret != 0) { |
| 874 |
dev_err(component->dev, "Failed to sync register cache: %d\n", |
| 875 |
ret); |
| 876 |
regcache_cache_only(alc5623->regmap, true); |
| 877 |
return ret; |
| 878 |
} |
| 879 |
|
| 880 |
return 0; |
| 881 |
} |
| 882 |
|
| 883 |
static int alc5623_probe(struct snd_soc_component *component) |
| 884 |
{ |
| 885 |
struct alc5623_priv *alc5623 = snd_soc_component_get_drvdata(component); |
| 886 |
struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component); |
| 887 |
|
| 888 |
alc5623_reset(component); |
| 889 |
|
| 890 |
if (alc5623->add_ctrl) { |
| 891 |
snd_soc_component_write(component, ALC5623_ADD_CTRL_REG, |
| 892 |
alc5623->add_ctrl); |
| 893 |
} |
| 894 |
|
| 895 |
if (alc5623->jack_det_ctrl) { |
| 896 |
snd_soc_component_write(component, ALC5623_JACK_DET_CTRL, |
| 897 |
alc5623->jack_det_ctrl); |
| 898 |
} |
| 899 |
|
| 900 |
switch (alc5623->id) { |
| 901 |
case 0x21: |
| 902 |
snd_soc_add_component_controls(component, alc5621_vol_snd_controls, |
| 903 |
ARRAY_SIZE(alc5621_vol_snd_controls)); |
| 904 |
break; |
| 905 |
case 0x22: |
| 906 |
snd_soc_add_component_controls(component, alc5622_vol_snd_controls, |
| 907 |
ARRAY_SIZE(alc5622_vol_snd_controls)); |
| 908 |
break; |
| 909 |
case 0x23: |
| 910 |
snd_soc_add_component_controls(component, alc5623_vol_snd_controls, |
| 911 |
ARRAY_SIZE(alc5623_vol_snd_controls)); |
| 912 |
break; |
| 913 |
default: |
| 914 |
return -EINVAL; |
| 915 |
} |
| 916 |
|
| 917 |
snd_soc_add_component_controls(component, alc5623_snd_controls, |
| 918 |
ARRAY_SIZE(alc5623_snd_controls)); |
| 919 |
|
| 920 |
snd_soc_dapm_new_controls(dapm, alc5623_dapm_widgets, |
| 921 |
ARRAY_SIZE(alc5623_dapm_widgets)); |
| 922 |
|
| 923 |
/* set up audio path interconnects */ |
| 924 |
snd_soc_dapm_add_routes(dapm, intercon, ARRAY_SIZE(intercon)); |
| 925 |
|
| 926 |
switch (alc5623->id) { |
| 927 |
case 0x21: |
| 928 |
case 0x22: |
| 929 |
snd_soc_dapm_new_controls(dapm, alc5623_dapm_amp_widgets, |
| 930 |
ARRAY_SIZE(alc5623_dapm_amp_widgets)); |
| 931 |
snd_soc_dapm_add_routes(dapm, intercon_amp_spk, |
| 932 |
ARRAY_SIZE(intercon_amp_spk)); |
| 933 |
break; |
| 934 |
case 0x23: |
| 935 |
snd_soc_dapm_add_routes(dapm, intercon_spk, |
| 936 |
ARRAY_SIZE(intercon_spk)); |
| 937 |
break; |
| 938 |
default: |
| 939 |
return -EINVAL; |
| 940 |
} |
| 941 |
|
| 942 |
return 0; |
| 943 |
} |
| 944 |
|
| 945 |
static const struct snd_soc_component_driver soc_component_device_alc5623 = { |
| 946 |
.probe = alc5623_probe, |
| 947 |
.suspend = alc5623_suspend, |
| 948 |
.resume = alc5623_resume, |
| 949 |
.set_bias_level = alc5623_set_bias_level, |
| 950 |
.suspend_bias_off = 1, |
| 951 |
.idle_bias_on = 1, |
| 952 |
.use_pmdown_time = 1, |
| 953 |
.endianness = 1, |
| 954 |
}; |
| 955 |
|
| 956 |
static const struct regmap_config alc5623_regmap = { |
| 957 |
.reg_bits = 8, |
| 958 |
.val_bits = 16, |
| 959 |
.reg_stride = 2, |
| 960 |
|
| 961 |
.max_register = ALC5623_VENDOR_ID2, |
| 962 |
.cache_type = REGCACHE_RBTREE, |
| 963 |
}; |
| 964 |
|
| 965 |
static const struct i2c_device_id alc5623_i2c_table[] = { |
| 966 |
{"alc5621", 0x21}, |
| 967 |
{"alc5622", 0x22}, |
| 968 |
{"alc5623", 0x23}, |
| 969 |
{} |
| 970 |
}; |
| 971 |
MODULE_DEVICE_TABLE(i2c, alc5623_i2c_table); |
| 972 |
|
| 973 |
/* |
| 974 |
* ALC5623 2 wire address is determined by A1 pin |
| 975 |
* state during powerup. |
| 976 |
* low = 0x1a |
| 977 |
* high = 0x1b |
| 978 |
*/ |
| 979 |
static int alc5623_i2c_probe(struct i2c_client *client) |
| 980 |
{ |
| 981 |
struct alc5623_platform_data *pdata; |
| 982 |
struct alc5623_priv *alc5623; |
| 983 |
struct device_node *np; |
| 984 |
unsigned int vid1, vid2; |
| 985 |
unsigned int matched_id; |
| 986 |
int ret; |
| 987 |
u32 val32; |
| 988 |
|
| 989 |
alc5623 = devm_kzalloc(&client->dev, sizeof(struct alc5623_priv), |
| 990 |
GFP_KERNEL); |
| 991 |
if (alc5623 == NULL) |
| 992 |
return -ENOMEM; |
| 993 |
|
| 994 |
alc5623->regmap = devm_regmap_init_i2c(client, &alc5623_regmap); |
| 995 |
if (IS_ERR(alc5623->regmap)) { |
| 996 |
ret = PTR_ERR(alc5623->regmap); |
| 997 |
dev_err(&client->dev, "Failed to initialise I/O: %d\n", ret); |
| 998 |
return ret; |
| 999 |
} |
| 1000 |
|
| 1001 |
ret = regmap_read(alc5623->regmap, ALC5623_VENDOR_ID1, &vid1); |
| 1002 |
if (ret < 0) { |
| 1003 |
dev_err(&client->dev, "failed to read vendor ID1: %d\n", ret); |
| 1004 |
return ret; |
| 1005 |
} |
| 1006 |
|
| 1007 |
ret = regmap_read(alc5623->regmap, ALC5623_VENDOR_ID2, &vid2); |
| 1008 |
if (ret < 0) { |
| 1009 |
dev_err(&client->dev, "failed to read vendor ID2: %d\n", ret); |
| 1010 |
return ret; |
| 1011 |
} |
| 1012 |
vid2 >>= 8; |
| 1013 |
|
| 1014 |
matched_id = (uintptr_t)i2c_get_match_data(client); |
| 1015 |
|
| 1016 |
if ((vid1 != 0x10ec) || (vid2 != matched_id)) { |
| 1017 |
dev_err(&client->dev, "unknown or wrong codec\n"); |
| 1018 |
dev_err(&client->dev, "Expected %x:%x, got %x:%x\n", |
| 1019 |
0x10ec, matched_id, |
| 1020 |
vid1, vid2); |
| 1021 |
return -ENODEV; |
| 1022 |
} |
| 1023 |
|
| 1024 |
dev_dbg(&client->dev, "Found codec id : alc56%02x\n", vid2); |
| 1025 |
|
| 1026 |
pdata = client->dev.platform_data; |
| 1027 |
if (pdata) { |
| 1028 |
alc5623->add_ctrl = pdata->add_ctrl; |
| 1029 |
alc5623->jack_det_ctrl = pdata->jack_det_ctrl; |
| 1030 |
} else { |
| 1031 |
if (client->dev.of_node) { |
| 1032 |
np = client->dev.of_node; |
| 1033 |
ret = of_property_read_u32(np, "add-ctrl", &val32); |
| 1034 |
if (!ret) |
| 1035 |
alc5623->add_ctrl = val32; |
| 1036 |
ret = of_property_read_u32(np, "jack-det-ctrl", &val32); |
| 1037 |
if (!ret) |
| 1038 |
alc5623->jack_det_ctrl = val32; |
| 1039 |
} |
| 1040 |
} |
| 1041 |
|
| 1042 |
alc5623->id = vid2; |
| 1043 |
switch (alc5623->id) { |
| 1044 |
case 0x21: |
| 1045 |
alc5623_dai.name = "alc5621-hifi"; |
| 1046 |
break; |
| 1047 |
case 0x22: |
| 1048 |
alc5623_dai.name = "alc5622-hifi"; |
| 1049 |
break; |
| 1050 |
case 0x23: |
| 1051 |
alc5623_dai.name = "alc5623-hifi"; |
| 1052 |
break; |
| 1053 |
default: |
| 1054 |
return -EINVAL; |
| 1055 |
} |
| 1056 |
|
| 1057 |
i2c_set_clientdata(client, alc5623); |
| 1058 |
|
| 1059 |
ret = devm_snd_soc_register_component(&client->dev, |
| 1060 |
&soc_component_device_alc5623, &alc5623_dai, 1); |
| 1061 |
if (ret != 0) |
| 1062 |
dev_err(&client->dev, "Failed to register codec: %d\n", ret); |
| 1063 |
|
| 1064 |
return ret; |
| 1065 |
} |
| 1066 |
|
| 1067 |
#ifdef CONFIG_OF |
| 1068 |
static const struct of_device_id alc5623_of_match[] = { |
| 1069 |
{ .compatible = "realtek,alc5623", }, |
| 1070 |
{ } |
| 1071 |
}; |
| 1072 |
MODULE_DEVICE_TABLE(of, alc5623_of_match); |
| 1073 |
#endif |
| 1074 |
|
| 1075 |
/* i2c codec control layer */ |
| 1076 |
static struct i2c_driver alc5623_i2c_driver = { |
| 1077 |
.driver = { |
| 1078 |
.name = "alc562x-codec", |
| 1079 |
.of_match_table = of_match_ptr(alc5623_of_match), |
| 1080 |
}, |
| 1081 |
.probe = alc5623_i2c_probe, |
| 1082 |
.id_table = alc5623_i2c_table, |
| 1083 |
}; |
| 1084 |
|
| 1085 |
module_i2c_driver(alc5623_i2c_driver); |
| 1086 |
|
| 1087 |
MODULE_DESCRIPTION("ASoC alc5621/2/3 driver"); |
| 1088 |
MODULE_AUTHOR("Arnaud Patard <[email protected]>"); |
| 1089 |
MODULE_LICENSE("GPL"); |