1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
248e27874SAdam Thomson /*
348e27874SAdam Thomson * da732x.c --- Dialog DA732X ALSA SoC Audio Driver
448e27874SAdam Thomson *
548e27874SAdam Thomson * Copyright (C) 2012 Dialog Semiconductor GmbH
648e27874SAdam Thomson *
748e27874SAdam Thomson * Author: Michal Hajduk <Michal.Hajduk@diasemi.com>
848e27874SAdam Thomson */
948e27874SAdam Thomson
1048e27874SAdam Thomson #include <linux/module.h>
1148e27874SAdam Thomson #include <linux/moduleparam.h>
1248e27874SAdam Thomson #include <linux/init.h>
1348e27874SAdam Thomson #include <linux/delay.h>
1448e27874SAdam Thomson #include <linux/pm.h>
1548e27874SAdam Thomson #include <linux/i2c.h>
1648e27874SAdam Thomson #include <linux/regmap.h>
1748e27874SAdam Thomson #include <linux/platform_device.h>
1848e27874SAdam Thomson #include <linux/slab.h>
1948e27874SAdam Thomson #include <linux/sysfs.h>
2048e27874SAdam Thomson #include <sound/core.h>
2148e27874SAdam Thomson #include <sound/pcm.h>
2248e27874SAdam Thomson #include <sound/pcm_params.h>
2348e27874SAdam Thomson #include <sound/soc.h>
2448e27874SAdam Thomson #include <sound/soc-dapm.h>
2548e27874SAdam Thomson #include <sound/initval.h>
2648e27874SAdam Thomson #include <sound/tlv.h>
2748e27874SAdam Thomson #include <asm/div64.h>
2848e27874SAdam Thomson
2948e27874SAdam Thomson #include "da732x.h"
3048e27874SAdam Thomson #include "da732x_reg.h"
3148e27874SAdam Thomson
3248e27874SAdam Thomson
3348e27874SAdam Thomson struct da732x_priv {
3448e27874SAdam Thomson struct regmap *regmap;
3548e27874SAdam Thomson
3648e27874SAdam Thomson unsigned int sysclk;
3748e27874SAdam Thomson bool pll_en;
3848e27874SAdam Thomson };
3948e27874SAdam Thomson
4048e27874SAdam Thomson /*
4148e27874SAdam Thomson * da732x register cache - default settings
4248e27874SAdam Thomson */
43c418a84aSAxel Lin static const struct reg_default da732x_reg_cache[] = {
4448e27874SAdam Thomson { DA732X_REG_REF1 , 0x02 },
4548e27874SAdam Thomson { DA732X_REG_BIAS_EN , 0x80 },
4648e27874SAdam Thomson { DA732X_REG_BIAS1 , 0x00 },
4748e27874SAdam Thomson { DA732X_REG_BIAS2 , 0x00 },
4848e27874SAdam Thomson { DA732X_REG_BIAS3 , 0x00 },
4948e27874SAdam Thomson { DA732X_REG_BIAS4 , 0x00 },
5048e27874SAdam Thomson { DA732X_REG_MICBIAS2 , 0x00 },
5148e27874SAdam Thomson { DA732X_REG_MICBIAS1 , 0x00 },
5248e27874SAdam Thomson { DA732X_REG_MICDET , 0x00 },
5348e27874SAdam Thomson { DA732X_REG_MIC1_PRE , 0x01 },
5448e27874SAdam Thomson { DA732X_REG_MIC1 , 0x40 },
5548e27874SAdam Thomson { DA732X_REG_MIC2_PRE , 0x01 },
5648e27874SAdam Thomson { DA732X_REG_MIC2 , 0x40 },
5748e27874SAdam Thomson { DA732X_REG_AUX1L , 0x75 },
5848e27874SAdam Thomson { DA732X_REG_AUX1R , 0x75 },
5948e27874SAdam Thomson { DA732X_REG_MIC3_PRE , 0x01 },
6048e27874SAdam Thomson { DA732X_REG_MIC3 , 0x40 },
6148e27874SAdam Thomson { DA732X_REG_INP_PINBIAS , 0x00 },
6248e27874SAdam Thomson { DA732X_REG_INP_ZC_EN , 0x00 },
6348e27874SAdam Thomson { DA732X_REG_INP_MUX , 0x50 },
6448e27874SAdam Thomson { DA732X_REG_HP_DET , 0x00 },
6548e27874SAdam Thomson { DA732X_REG_HPL_DAC_OFFSET , 0x00 },
6648e27874SAdam Thomson { DA732X_REG_HPL_DAC_OFF_CNTL , 0x00 },
6748e27874SAdam Thomson { DA732X_REG_HPL_OUT_OFFSET , 0x00 },
6848e27874SAdam Thomson { DA732X_REG_HPL , 0x40 },
6948e27874SAdam Thomson { DA732X_REG_HPL_VOL , 0x0F },
7048e27874SAdam Thomson { DA732X_REG_HPR_DAC_OFFSET , 0x00 },
7148e27874SAdam Thomson { DA732X_REG_HPR_DAC_OFF_CNTL , 0x00 },
7248e27874SAdam Thomson { DA732X_REG_HPR_OUT_OFFSET , 0x00 },
7348e27874SAdam Thomson { DA732X_REG_HPR , 0x40 },
7448e27874SAdam Thomson { DA732X_REG_HPR_VOL , 0x0F },
7548e27874SAdam Thomson { DA732X_REG_LIN2 , 0x4F },
7648e27874SAdam Thomson { DA732X_REG_LIN3 , 0x4F },
7748e27874SAdam Thomson { DA732X_REG_LIN4 , 0x4F },
7848e27874SAdam Thomson { DA732X_REG_OUT_ZC_EN , 0x00 },
7948e27874SAdam Thomson { DA732X_REG_HP_LIN1_GNDSEL , 0x00 },
8048e27874SAdam Thomson { DA732X_REG_CP_HP1 , 0x0C },
8148e27874SAdam Thomson { DA732X_REG_CP_HP2 , 0x03 },
8248e27874SAdam Thomson { DA732X_REG_CP_CTRL1 , 0x00 },
8348e27874SAdam Thomson { DA732X_REG_CP_CTRL2 , 0x99 },
8448e27874SAdam Thomson { DA732X_REG_CP_CTRL3 , 0x25 },
8548e27874SAdam Thomson { DA732X_REG_CP_LEVEL_MASK , 0x3F },
8648e27874SAdam Thomson { DA732X_REG_CP_DET , 0x00 },
8748e27874SAdam Thomson { DA732X_REG_CP_STATUS , 0x00 },
8848e27874SAdam Thomson { DA732X_REG_CP_THRESH1 , 0x00 },
8948e27874SAdam Thomson { DA732X_REG_CP_THRESH2 , 0x00 },
9048e27874SAdam Thomson { DA732X_REG_CP_THRESH3 , 0x00 },
9148e27874SAdam Thomson { DA732X_REG_CP_THRESH4 , 0x00 },
9248e27874SAdam Thomson { DA732X_REG_CP_THRESH5 , 0x00 },
9348e27874SAdam Thomson { DA732X_REG_CP_THRESH6 , 0x00 },
9448e27874SAdam Thomson { DA732X_REG_CP_THRESH7 , 0x00 },
9548e27874SAdam Thomson { DA732X_REG_CP_THRESH8 , 0x00 },
9648e27874SAdam Thomson { DA732X_REG_PLL_DIV_LO , 0x00 },
9748e27874SAdam Thomson { DA732X_REG_PLL_DIV_MID , 0x00 },
9848e27874SAdam Thomson { DA732X_REG_PLL_DIV_HI , 0x00 },
9948e27874SAdam Thomson { DA732X_REG_PLL_CTRL , 0x02 },
10048e27874SAdam Thomson { DA732X_REG_CLK_CTRL , 0xaa },
10148e27874SAdam Thomson { DA732X_REG_CLK_DSP , 0x07 },
10248e27874SAdam Thomson { DA732X_REG_CLK_EN1 , 0x00 },
10348e27874SAdam Thomson { DA732X_REG_CLK_EN2 , 0x00 },
10448e27874SAdam Thomson { DA732X_REG_CLK_EN3 , 0x00 },
10548e27874SAdam Thomson { DA732X_REG_CLK_EN4 , 0x00 },
10648e27874SAdam Thomson { DA732X_REG_CLK_EN5 , 0x00 },
10748e27874SAdam Thomson { DA732X_REG_AIF_MCLK , 0x00 },
10848e27874SAdam Thomson { DA732X_REG_AIFA1 , 0x02 },
10948e27874SAdam Thomson { DA732X_REG_AIFA2 , 0x00 },
11048e27874SAdam Thomson { DA732X_REG_AIFA3 , 0x08 },
11148e27874SAdam Thomson { DA732X_REG_AIFB1 , 0x02 },
11248e27874SAdam Thomson { DA732X_REG_AIFB2 , 0x00 },
11348e27874SAdam Thomson { DA732X_REG_AIFB3 , 0x08 },
11448e27874SAdam Thomson { DA732X_REG_PC_CTRL , 0xC0 },
11548e27874SAdam Thomson { DA732X_REG_DATA_ROUTE , 0x00 },
11648e27874SAdam Thomson { DA732X_REG_DSP_CTRL , 0x00 },
11748e27874SAdam Thomson { DA732X_REG_CIF_CTRL2 , 0x00 },
11848e27874SAdam Thomson { DA732X_REG_HANDSHAKE , 0x00 },
11948e27874SAdam Thomson { DA732X_REG_SPARE1_OUT , 0x00 },
12048e27874SAdam Thomson { DA732X_REG_SPARE2_OUT , 0x00 },
12148e27874SAdam Thomson { DA732X_REG_SPARE1_IN , 0x00 },
12248e27874SAdam Thomson { DA732X_REG_ADC1_PD , 0x00 },
12348e27874SAdam Thomson { DA732X_REG_ADC1_HPF , 0x00 },
12448e27874SAdam Thomson { DA732X_REG_ADC1_SEL , 0x00 },
12548e27874SAdam Thomson { DA732X_REG_ADC1_EQ12 , 0x00 },
12648e27874SAdam Thomson { DA732X_REG_ADC1_EQ34 , 0x00 },
12748e27874SAdam Thomson { DA732X_REG_ADC1_EQ5 , 0x00 },
12848e27874SAdam Thomson { DA732X_REG_ADC2_PD , 0x00 },
12948e27874SAdam Thomson { DA732X_REG_ADC2_HPF , 0x00 },
13048e27874SAdam Thomson { DA732X_REG_ADC2_SEL , 0x00 },
13148e27874SAdam Thomson { DA732X_REG_ADC2_EQ12 , 0x00 },
13248e27874SAdam Thomson { DA732X_REG_ADC2_EQ34 , 0x00 },
13348e27874SAdam Thomson { DA732X_REG_ADC2_EQ5 , 0x00 },
13448e27874SAdam Thomson { DA732X_REG_DAC1_HPF , 0x00 },
13548e27874SAdam Thomson { DA732X_REG_DAC1_L_VOL , 0x00 },
13648e27874SAdam Thomson { DA732X_REG_DAC1_R_VOL , 0x00 },
13748e27874SAdam Thomson { DA732X_REG_DAC1_SEL , 0x00 },
13848e27874SAdam Thomson { DA732X_REG_DAC1_SOFTMUTE , 0x00 },
13948e27874SAdam Thomson { DA732X_REG_DAC1_EQ12 , 0x00 },
14048e27874SAdam Thomson { DA732X_REG_DAC1_EQ34 , 0x00 },
14148e27874SAdam Thomson { DA732X_REG_DAC1_EQ5 , 0x00 },
14248e27874SAdam Thomson { DA732X_REG_DAC2_HPF , 0x00 },
14348e27874SAdam Thomson { DA732X_REG_DAC2_L_VOL , 0x00 },
14448e27874SAdam Thomson { DA732X_REG_DAC2_R_VOL , 0x00 },
14548e27874SAdam Thomson { DA732X_REG_DAC2_SEL , 0x00 },
14648e27874SAdam Thomson { DA732X_REG_DAC2_SOFTMUTE , 0x00 },
14748e27874SAdam Thomson { DA732X_REG_DAC2_EQ12 , 0x00 },
14848e27874SAdam Thomson { DA732X_REG_DAC2_EQ34 , 0x00 },
14948e27874SAdam Thomson { DA732X_REG_DAC2_EQ5 , 0x00 },
15048e27874SAdam Thomson { DA732X_REG_DAC3_HPF , 0x00 },
15148e27874SAdam Thomson { DA732X_REG_DAC3_VOL , 0x00 },
15248e27874SAdam Thomson { DA732X_REG_DAC3_SEL , 0x00 },
15348e27874SAdam Thomson { DA732X_REG_DAC3_SOFTMUTE , 0x00 },
15448e27874SAdam Thomson { DA732X_REG_DAC3_EQ12 , 0x00 },
15548e27874SAdam Thomson { DA732X_REG_DAC3_EQ34 , 0x00 },
15648e27874SAdam Thomson { DA732X_REG_DAC3_EQ5 , 0x00 },
15748e27874SAdam Thomson { DA732X_REG_BIQ_BYP , 0x00 },
15848e27874SAdam Thomson { DA732X_REG_DMA_CMD , 0x00 },
15948e27874SAdam Thomson { DA732X_REG_DMA_ADDR0 , 0x00 },
16048e27874SAdam Thomson { DA732X_REG_DMA_ADDR1 , 0x00 },
16148e27874SAdam Thomson { DA732X_REG_DMA_DATA0 , 0x00 },
16248e27874SAdam Thomson { DA732X_REG_DMA_DATA1 , 0x00 },
16348e27874SAdam Thomson { DA732X_REG_DMA_DATA2 , 0x00 },
16448e27874SAdam Thomson { DA732X_REG_DMA_DATA3 , 0x00 },
16548e27874SAdam Thomson { DA732X_REG_UNLOCK , 0x00 },
16648e27874SAdam Thomson };
16748e27874SAdam Thomson
da732x_get_input_div(struct snd_soc_component * component,int sysclk)168192ce2fbSKuninori Morimoto static inline int da732x_get_input_div(struct snd_soc_component *component, int sysclk)
16948e27874SAdam Thomson {
17048e27874SAdam Thomson int val;
17148e27874SAdam Thomson
17248e27874SAdam Thomson if (sysclk < DA732X_MCLK_10MHZ) {
173945b0b58SPierre-Louis Bossart val = DA732X_MCLK_VAL_0_10MHZ;
17448e27874SAdam Thomson } else if ((sysclk >= DA732X_MCLK_10MHZ) &&
17548e27874SAdam Thomson (sysclk < DA732X_MCLK_20MHZ)) {
176945b0b58SPierre-Louis Bossart val = DA732X_MCLK_VAL_10_20MHZ;
17748e27874SAdam Thomson } else if ((sysclk >= DA732X_MCLK_20MHZ) &&
17848e27874SAdam Thomson (sysclk < DA732X_MCLK_40MHZ)) {
179945b0b58SPierre-Louis Bossart val = DA732X_MCLK_VAL_20_40MHZ;
18048e27874SAdam Thomson } else if ((sysclk >= DA732X_MCLK_40MHZ) &&
18148e27874SAdam Thomson (sysclk <= DA732X_MCLK_54MHZ)) {
182945b0b58SPierre-Louis Bossart val = DA732X_MCLK_VAL_40_54MHZ;
18348e27874SAdam Thomson } else {
18448e27874SAdam Thomson return -EINVAL;
18548e27874SAdam Thomson }
18648e27874SAdam Thomson
187192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_PLL_CTRL, val);
18848e27874SAdam Thomson
189945b0b58SPierre-Louis Bossart return val;
19048e27874SAdam Thomson }
19148e27874SAdam Thomson
da732x_set_charge_pump(struct snd_soc_component * component,int state)192192ce2fbSKuninori Morimoto static void da732x_set_charge_pump(struct snd_soc_component *component, int state)
19348e27874SAdam Thomson {
19448e27874SAdam Thomson switch (state) {
19548e27874SAdam Thomson case DA732X_ENABLE_CP:
196192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_CLK_EN2, DA732X_CP_CLK_EN);
197192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_CP_HP2, DA732X_HP_CP_EN |
19848e27874SAdam Thomson DA732X_HP_CP_REG | DA732X_HP_CP_PULSESKIP);
199192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_CP_CTRL1, DA732X_CP_EN |
20048e27874SAdam Thomson DA732X_CP_CTRL_CPVDD1);
201192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_CP_CTRL2,
20248e27874SAdam Thomson DA732X_CP_MANAGE_MAGNITUDE | DA732X_CP_BOOST);
203192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_CP_CTRL3, DA732X_CP_1MHZ);
20448e27874SAdam Thomson break;
20548e27874SAdam Thomson case DA732X_DISABLE_CP:
206192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_CLK_EN2, DA732X_CP_CLK_DIS);
207192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_CP_HP2, DA732X_HP_CP_DIS);
208192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_CP_CTRL1, DA723X_CP_DIS);
20948e27874SAdam Thomson break;
21048e27874SAdam Thomson default:
211cd9241e4SMasanari Iida pr_err("Wrong charge pump state\n");
21248e27874SAdam Thomson break;
21348e27874SAdam Thomson }
21448e27874SAdam Thomson }
21548e27874SAdam Thomson
21648e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(mic_boost_tlv, DA732X_MIC_PRE_VOL_DB_MIN,
21748e27874SAdam Thomson DA732X_MIC_PRE_VOL_DB_INC, 0);
21848e27874SAdam Thomson
21948e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(mic_pga_tlv, DA732X_MIC_VOL_DB_MIN,
22048e27874SAdam Thomson DA732X_MIC_VOL_DB_INC, 0);
22148e27874SAdam Thomson
22248e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(aux_pga_tlv, DA732X_AUX_VOL_DB_MIN,
22348e27874SAdam Thomson DA732X_AUX_VOL_DB_INC, 0);
22448e27874SAdam Thomson
22548e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(hp_pga_tlv, DA732X_HP_VOL_DB_MIN,
22648e27874SAdam Thomson DA732X_AUX_VOL_DB_INC, 0);
22748e27874SAdam Thomson
22848e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(lin2_pga_tlv, DA732X_LIN2_VOL_DB_MIN,
22948e27874SAdam Thomson DA732X_LIN2_VOL_DB_INC, 0);
23048e27874SAdam Thomson
23148e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(lin3_pga_tlv, DA732X_LIN3_VOL_DB_MIN,
23248e27874SAdam Thomson DA732X_LIN3_VOL_DB_INC, 0);
23348e27874SAdam Thomson
23448e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(lin4_pga_tlv, DA732X_LIN4_VOL_DB_MIN,
23548e27874SAdam Thomson DA732X_LIN4_VOL_DB_INC, 0);
23648e27874SAdam Thomson
23748e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(adc_pga_tlv, DA732X_ADC_VOL_DB_MIN,
23848e27874SAdam Thomson DA732X_ADC_VOL_DB_INC, 0);
23948e27874SAdam Thomson
24048e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(dac_pga_tlv, DA732X_DAC_VOL_DB_MIN,
24148e27874SAdam Thomson DA732X_DAC_VOL_DB_INC, 0);
24248e27874SAdam Thomson
24348e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(eq_band_pga_tlv, DA732X_EQ_BAND_VOL_DB_MIN,
24448e27874SAdam Thomson DA732X_EQ_BAND_VOL_DB_INC, 0);
24548e27874SAdam Thomson
24648e27874SAdam Thomson static const DECLARE_TLV_DB_SCALE(eq_overall_tlv, DA732X_EQ_OVERALL_VOL_DB_MIN,
24748e27874SAdam Thomson DA732X_EQ_OVERALL_VOL_DB_INC, 0);
24848e27874SAdam Thomson
24948e27874SAdam Thomson /* High Pass Filter */
25048e27874SAdam Thomson static const char *da732x_hpf_mode[] = {
25148e27874SAdam Thomson "Disable", "Music", "Voice",
25248e27874SAdam Thomson };
25348e27874SAdam Thomson
25448e27874SAdam Thomson static const char *da732x_hpf_music[] = {
25548e27874SAdam Thomson "1.8Hz", "3.75Hz", "7.5Hz", "15Hz",
25648e27874SAdam Thomson };
25748e27874SAdam Thomson
25848e27874SAdam Thomson static const char *da732x_hpf_voice[] = {
25948e27874SAdam Thomson "2.5Hz", "25Hz", "50Hz", "100Hz",
26048e27874SAdam Thomson "150Hz", "200Hz", "300Hz", "400Hz"
26148e27874SAdam Thomson };
26248e27874SAdam Thomson
2637e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_dac1_hpf_mode_enum,
2647e509108STakashi Iwai DA732X_REG_DAC1_HPF, DA732X_HPF_MODE_SHIFT,
2657e509108STakashi Iwai da732x_hpf_mode);
26648e27874SAdam Thomson
2677e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_dac2_hpf_mode_enum,
2687e509108STakashi Iwai DA732X_REG_DAC2_HPF, DA732X_HPF_MODE_SHIFT,
2697e509108STakashi Iwai da732x_hpf_mode);
27048e27874SAdam Thomson
2717e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_dac3_hpf_mode_enum,
2727e509108STakashi Iwai DA732X_REG_DAC3_HPF, DA732X_HPF_MODE_SHIFT,
2737e509108STakashi Iwai da732x_hpf_mode);
27448e27874SAdam Thomson
2757e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_adc1_hpf_mode_enum,
2767e509108STakashi Iwai DA732X_REG_ADC1_HPF, DA732X_HPF_MODE_SHIFT,
2777e509108STakashi Iwai da732x_hpf_mode);
27848e27874SAdam Thomson
2797e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_adc2_hpf_mode_enum,
2807e509108STakashi Iwai DA732X_REG_ADC2_HPF, DA732X_HPF_MODE_SHIFT,
2817e509108STakashi Iwai da732x_hpf_mode);
28248e27874SAdam Thomson
2837e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_dac1_hp_filter_enum,
2847e509108STakashi Iwai DA732X_REG_DAC1_HPF, DA732X_HPF_MUSIC_SHIFT,
2857e509108STakashi Iwai da732x_hpf_music);
28648e27874SAdam Thomson
2877e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_dac2_hp_filter_enum,
2887e509108STakashi Iwai DA732X_REG_DAC2_HPF, DA732X_HPF_MUSIC_SHIFT,
2897e509108STakashi Iwai da732x_hpf_music);
29048e27874SAdam Thomson
2917e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_dac3_hp_filter_enum,
2927e509108STakashi Iwai DA732X_REG_DAC3_HPF, DA732X_HPF_MUSIC_SHIFT,
2937e509108STakashi Iwai da732x_hpf_music);
29448e27874SAdam Thomson
2957e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_adc1_hp_filter_enum,
2967e509108STakashi Iwai DA732X_REG_ADC1_HPF, DA732X_HPF_MUSIC_SHIFT,
2977e509108STakashi Iwai da732x_hpf_music);
29848e27874SAdam Thomson
2997e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_adc2_hp_filter_enum,
3007e509108STakashi Iwai DA732X_REG_ADC2_HPF, DA732X_HPF_MUSIC_SHIFT,
3017e509108STakashi Iwai da732x_hpf_music);
30248e27874SAdam Thomson
3037e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_dac1_voice_filter_enum,
3047e509108STakashi Iwai DA732X_REG_DAC1_HPF, DA732X_HPF_VOICE_SHIFT,
3057e509108STakashi Iwai da732x_hpf_voice);
30648e27874SAdam Thomson
3077e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_dac2_voice_filter_enum,
3087e509108STakashi Iwai DA732X_REG_DAC2_HPF, DA732X_HPF_VOICE_SHIFT,
3097e509108STakashi Iwai da732x_hpf_voice);
31048e27874SAdam Thomson
3117e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_dac3_voice_filter_enum,
3127e509108STakashi Iwai DA732X_REG_DAC3_HPF, DA732X_HPF_VOICE_SHIFT,
3137e509108STakashi Iwai da732x_hpf_voice);
31448e27874SAdam Thomson
3157e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_adc1_voice_filter_enum,
3167e509108STakashi Iwai DA732X_REG_ADC1_HPF, DA732X_HPF_VOICE_SHIFT,
3177e509108STakashi Iwai da732x_hpf_voice);
31848e27874SAdam Thomson
3197e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_adc2_voice_filter_enum,
3207e509108STakashi Iwai DA732X_REG_ADC2_HPF, DA732X_HPF_VOICE_SHIFT,
3217e509108STakashi Iwai da732x_hpf_voice);
32248e27874SAdam Thomson
da732x_hpf_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)32348e27874SAdam Thomson static int da732x_hpf_set(struct snd_kcontrol *kcontrol,
32448e27874SAdam Thomson struct snd_ctl_elem_value *ucontrol)
32548e27874SAdam Thomson {
326192ce2fbSKuninori Morimoto struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
32748e27874SAdam Thomson struct soc_enum *enum_ctrl = (struct soc_enum *)kcontrol->private_value;
32848e27874SAdam Thomson unsigned int reg = enum_ctrl->reg;
329fe9aba13STakashi Iwai unsigned int sel = ucontrol->value.enumerated.item[0];
33048e27874SAdam Thomson unsigned int bits;
33148e27874SAdam Thomson
33248e27874SAdam Thomson switch (sel) {
33348e27874SAdam Thomson case DA732X_HPF_DISABLED:
33448e27874SAdam Thomson bits = DA732X_HPF_DIS;
33548e27874SAdam Thomson break;
33648e27874SAdam Thomson case DA732X_HPF_VOICE:
33748e27874SAdam Thomson bits = DA732X_HPF_VOICE_EN;
33848e27874SAdam Thomson break;
33948e27874SAdam Thomson case DA732X_HPF_MUSIC:
34048e27874SAdam Thomson bits = DA732X_HPF_MUSIC_EN;
34148e27874SAdam Thomson break;
34248e27874SAdam Thomson default:
34348e27874SAdam Thomson return -EINVAL;
34448e27874SAdam Thomson }
34548e27874SAdam Thomson
346192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, reg, DA732X_HPF_MASK, bits);
34748e27874SAdam Thomson
34848e27874SAdam Thomson return 0;
34948e27874SAdam Thomson }
35048e27874SAdam Thomson
da732x_hpf_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)35148e27874SAdam Thomson static int da732x_hpf_get(struct snd_kcontrol *kcontrol,
35248e27874SAdam Thomson struct snd_ctl_elem_value *ucontrol)
35348e27874SAdam Thomson {
354192ce2fbSKuninori Morimoto struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol);
35548e27874SAdam Thomson struct soc_enum *enum_ctrl = (struct soc_enum *)kcontrol->private_value;
35648e27874SAdam Thomson unsigned int reg = enum_ctrl->reg;
35748e27874SAdam Thomson int val;
35848e27874SAdam Thomson
3592925b582SKuninori Morimoto val = snd_soc_component_read(component, reg) & DA732X_HPF_MASK;
36048e27874SAdam Thomson
36148e27874SAdam Thomson switch (val) {
36248e27874SAdam Thomson case DA732X_HPF_VOICE_EN:
363fe9aba13STakashi Iwai ucontrol->value.enumerated.item[0] = DA732X_HPF_VOICE;
36448e27874SAdam Thomson break;
36548e27874SAdam Thomson case DA732X_HPF_MUSIC_EN:
366fe9aba13STakashi Iwai ucontrol->value.enumerated.item[0] = DA732X_HPF_MUSIC;
36748e27874SAdam Thomson break;
36848e27874SAdam Thomson default:
369fe9aba13STakashi Iwai ucontrol->value.enumerated.item[0] = DA732X_HPF_DISABLED;
37048e27874SAdam Thomson break;
37148e27874SAdam Thomson }
37248e27874SAdam Thomson
37348e27874SAdam Thomson return 0;
37448e27874SAdam Thomson }
37548e27874SAdam Thomson
37648e27874SAdam Thomson static const struct snd_kcontrol_new da732x_snd_controls[] = {
37748e27874SAdam Thomson /* Input PGAs */
37848e27874SAdam Thomson SOC_SINGLE_RANGE_TLV("MIC1 Boost Volume", DA732X_REG_MIC1_PRE,
37948e27874SAdam Thomson DA732X_MICBOOST_SHIFT, DA732X_MICBOOST_MIN,
38048e27874SAdam Thomson DA732X_MICBOOST_MAX, 0, mic_boost_tlv),
38148e27874SAdam Thomson SOC_SINGLE_RANGE_TLV("MIC2 Boost Volume", DA732X_REG_MIC2_PRE,
38248e27874SAdam Thomson DA732X_MICBOOST_SHIFT, DA732X_MICBOOST_MIN,
38348e27874SAdam Thomson DA732X_MICBOOST_MAX, 0, mic_boost_tlv),
38448e27874SAdam Thomson SOC_SINGLE_RANGE_TLV("MIC3 Boost Volume", DA732X_REG_MIC3_PRE,
38548e27874SAdam Thomson DA732X_MICBOOST_SHIFT, DA732X_MICBOOST_MIN,
38648e27874SAdam Thomson DA732X_MICBOOST_MAX, 0, mic_boost_tlv),
38748e27874SAdam Thomson
38848e27874SAdam Thomson /* MICs */
38948e27874SAdam Thomson SOC_SINGLE("MIC1 Switch", DA732X_REG_MIC1, DA732X_MIC_MUTE_SHIFT,
39048e27874SAdam Thomson DA732X_SWITCH_MAX, DA732X_INVERT),
39148e27874SAdam Thomson SOC_SINGLE_RANGE_TLV("MIC1 Volume", DA732X_REG_MIC1,
39248e27874SAdam Thomson DA732X_MIC_VOL_SHIFT, DA732X_MIC_VOL_VAL_MIN,
39348e27874SAdam Thomson DA732X_MIC_VOL_VAL_MAX, 0, mic_pga_tlv),
39448e27874SAdam Thomson SOC_SINGLE("MIC2 Switch", DA732X_REG_MIC2, DA732X_MIC_MUTE_SHIFT,
39548e27874SAdam Thomson DA732X_SWITCH_MAX, DA732X_INVERT),
39648e27874SAdam Thomson SOC_SINGLE_RANGE_TLV("MIC2 Volume", DA732X_REG_MIC2,
39748e27874SAdam Thomson DA732X_MIC_VOL_SHIFT, DA732X_MIC_VOL_VAL_MIN,
39848e27874SAdam Thomson DA732X_MIC_VOL_VAL_MAX, 0, mic_pga_tlv),
39948e27874SAdam Thomson SOC_SINGLE("MIC3 Switch", DA732X_REG_MIC3, DA732X_MIC_MUTE_SHIFT,
40048e27874SAdam Thomson DA732X_SWITCH_MAX, DA732X_INVERT),
40148e27874SAdam Thomson SOC_SINGLE_RANGE_TLV("MIC3 Volume", DA732X_REG_MIC3,
40248e27874SAdam Thomson DA732X_MIC_VOL_SHIFT, DA732X_MIC_VOL_VAL_MIN,
40348e27874SAdam Thomson DA732X_MIC_VOL_VAL_MAX, 0, mic_pga_tlv),
40448e27874SAdam Thomson
40548e27874SAdam Thomson /* AUXs */
40648e27874SAdam Thomson SOC_SINGLE("AUX1L Switch", DA732X_REG_AUX1L, DA732X_AUX_MUTE_SHIFT,
40748e27874SAdam Thomson DA732X_SWITCH_MAX, DA732X_INVERT),
40848e27874SAdam Thomson SOC_SINGLE_TLV("AUX1L Volume", DA732X_REG_AUX1L,
40948e27874SAdam Thomson DA732X_AUX_VOL_SHIFT, DA732X_AUX_VOL_VAL_MAX,
41048e27874SAdam Thomson DA732X_NO_INVERT, aux_pga_tlv),
41148e27874SAdam Thomson SOC_SINGLE("AUX1R Switch", DA732X_REG_AUX1R, DA732X_AUX_MUTE_SHIFT,
41248e27874SAdam Thomson DA732X_SWITCH_MAX, DA732X_INVERT),
41348e27874SAdam Thomson SOC_SINGLE_TLV("AUX1R Volume", DA732X_REG_AUX1R,
41448e27874SAdam Thomson DA732X_AUX_VOL_SHIFT, DA732X_AUX_VOL_VAL_MAX,
41548e27874SAdam Thomson DA732X_NO_INVERT, aux_pga_tlv),
41648e27874SAdam Thomson
41748e27874SAdam Thomson /* ADCs */
41848e27874SAdam Thomson SOC_DOUBLE_TLV("ADC1 Volume", DA732X_REG_ADC1_SEL,
41948e27874SAdam Thomson DA732X_ADCL_VOL_SHIFT, DA732X_ADCR_VOL_SHIFT,
42048e27874SAdam Thomson DA732X_ADC_VOL_VAL_MAX, DA732X_INVERT, adc_pga_tlv),
42148e27874SAdam Thomson
42248e27874SAdam Thomson SOC_DOUBLE_TLV("ADC2 Volume", DA732X_REG_ADC2_SEL,
42348e27874SAdam Thomson DA732X_ADCL_VOL_SHIFT, DA732X_ADCR_VOL_SHIFT,
42448e27874SAdam Thomson DA732X_ADC_VOL_VAL_MAX, DA732X_INVERT, adc_pga_tlv),
42548e27874SAdam Thomson
42648e27874SAdam Thomson /* DACs */
42748e27874SAdam Thomson SOC_DOUBLE("Digital Playback DAC12 Switch", DA732X_REG_DAC1_SEL,
42848e27874SAdam Thomson DA732X_DACL_MUTE_SHIFT, DA732X_DACR_MUTE_SHIFT,
42948e27874SAdam Thomson DA732X_SWITCH_MAX, DA732X_INVERT),
43048e27874SAdam Thomson SOC_DOUBLE_R_TLV("Digital Playback DAC12 Volume", DA732X_REG_DAC1_L_VOL,
43148e27874SAdam Thomson DA732X_REG_DAC1_R_VOL, DA732X_DAC_VOL_SHIFT,
43248e27874SAdam Thomson DA732X_DAC_VOL_VAL_MAX, DA732X_INVERT, dac_pga_tlv),
43348e27874SAdam Thomson SOC_SINGLE("Digital Playback DAC3 Switch", DA732X_REG_DAC2_SEL,
43448e27874SAdam Thomson DA732X_DACL_MUTE_SHIFT, DA732X_SWITCH_MAX, DA732X_INVERT),
43548e27874SAdam Thomson SOC_SINGLE_TLV("Digital Playback DAC3 Volume", DA732X_REG_DAC2_L_VOL,
43648e27874SAdam Thomson DA732X_DAC_VOL_SHIFT, DA732X_DAC_VOL_VAL_MAX,
43748e27874SAdam Thomson DA732X_INVERT, dac_pga_tlv),
43848e27874SAdam Thomson SOC_SINGLE("Digital Playback DAC4 Switch", DA732X_REG_DAC2_SEL,
43948e27874SAdam Thomson DA732X_DACR_MUTE_SHIFT, DA732X_SWITCH_MAX, DA732X_INVERT),
44048e27874SAdam Thomson SOC_SINGLE_TLV("Digital Playback DAC4 Volume", DA732X_REG_DAC2_R_VOL,
44148e27874SAdam Thomson DA732X_DAC_VOL_SHIFT, DA732X_DAC_VOL_VAL_MAX,
44248e27874SAdam Thomson DA732X_INVERT, dac_pga_tlv),
44348e27874SAdam Thomson SOC_SINGLE("Digital Playback DAC5 Switch", DA732X_REG_DAC3_SEL,
44448e27874SAdam Thomson DA732X_DACL_MUTE_SHIFT, DA732X_SWITCH_MAX, DA732X_INVERT),
44548e27874SAdam Thomson SOC_SINGLE_TLV("Digital Playback DAC5 Volume", DA732X_REG_DAC3_VOL,
44648e27874SAdam Thomson DA732X_DAC_VOL_SHIFT, DA732X_DAC_VOL_VAL_MAX,
44748e27874SAdam Thomson DA732X_INVERT, dac_pga_tlv),
44848e27874SAdam Thomson
44948e27874SAdam Thomson /* High Pass Filters */
45048e27874SAdam Thomson SOC_ENUM_EXT("DAC1 High Pass Filter Mode",
45148e27874SAdam Thomson da732x_dac1_hpf_mode_enum, da732x_hpf_get, da732x_hpf_set),
45248e27874SAdam Thomson SOC_ENUM("DAC1 High Pass Filter", da732x_dac1_hp_filter_enum),
45348e27874SAdam Thomson SOC_ENUM("DAC1 Voice Filter", da732x_dac1_voice_filter_enum),
45448e27874SAdam Thomson
45548e27874SAdam Thomson SOC_ENUM_EXT("DAC2 High Pass Filter Mode",
45648e27874SAdam Thomson da732x_dac2_hpf_mode_enum, da732x_hpf_get, da732x_hpf_set),
45748e27874SAdam Thomson SOC_ENUM("DAC2 High Pass Filter", da732x_dac2_hp_filter_enum),
45848e27874SAdam Thomson SOC_ENUM("DAC2 Voice Filter", da732x_dac2_voice_filter_enum),
45948e27874SAdam Thomson
46048e27874SAdam Thomson SOC_ENUM_EXT("DAC3 High Pass Filter Mode",
46148e27874SAdam Thomson da732x_dac3_hpf_mode_enum, da732x_hpf_get, da732x_hpf_set),
46248e27874SAdam Thomson SOC_ENUM("DAC3 High Pass Filter", da732x_dac3_hp_filter_enum),
46348e27874SAdam Thomson SOC_ENUM("DAC3 Filter Mode", da732x_dac3_voice_filter_enum),
46448e27874SAdam Thomson
46548e27874SAdam Thomson SOC_ENUM_EXT("ADC1 High Pass Filter Mode",
46648e27874SAdam Thomson da732x_adc1_hpf_mode_enum, da732x_hpf_get, da732x_hpf_set),
46748e27874SAdam Thomson SOC_ENUM("ADC1 High Pass Filter", da732x_adc1_hp_filter_enum),
46848e27874SAdam Thomson SOC_ENUM("ADC1 Voice Filter", da732x_adc1_voice_filter_enum),
46948e27874SAdam Thomson
47048e27874SAdam Thomson SOC_ENUM_EXT("ADC2 High Pass Filter Mode",
47148e27874SAdam Thomson da732x_adc2_hpf_mode_enum, da732x_hpf_get, da732x_hpf_set),
47248e27874SAdam Thomson SOC_ENUM("ADC2 High Pass Filter", da732x_adc2_hp_filter_enum),
47348e27874SAdam Thomson SOC_ENUM("ADC2 Voice Filter", da732x_adc2_voice_filter_enum),
47448e27874SAdam Thomson
47548e27874SAdam Thomson /* Equalizers */
47648e27874SAdam Thomson SOC_SINGLE("ADC1 EQ Switch", DA732X_REG_ADC1_EQ5,
47748e27874SAdam Thomson DA732X_EQ_EN_SHIFT, DA732X_EQ_EN_MAX, DA732X_NO_INVERT),
47848e27874SAdam Thomson SOC_SINGLE_TLV("ADC1 EQ Band 1 Volume", DA732X_REG_ADC1_EQ12,
47948e27874SAdam Thomson DA732X_EQ_BAND1_SHIFT, DA732X_EQ_VOL_VAL_MAX,
48048e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
48148e27874SAdam Thomson SOC_SINGLE_TLV("ADC1 EQ Band 2 Volume", DA732X_REG_ADC1_EQ12,
48248e27874SAdam Thomson DA732X_EQ_BAND2_SHIFT, DA732X_EQ_VOL_VAL_MAX,
48348e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
48448e27874SAdam Thomson SOC_SINGLE_TLV("ADC1 EQ Band 3 Volume", DA732X_REG_ADC1_EQ34,
48548e27874SAdam Thomson DA732X_EQ_BAND3_SHIFT, DA732X_EQ_VOL_VAL_MAX,
48648e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
48748e27874SAdam Thomson SOC_SINGLE_TLV("ADC1 EQ Band 4 Volume", DA732X_REG_ADC1_EQ34,
48848e27874SAdam Thomson DA732X_EQ_BAND4_SHIFT, DA732X_EQ_VOL_VAL_MAX,
48948e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
49048e27874SAdam Thomson SOC_SINGLE_TLV("ADC1 EQ Band 5 Volume", DA732X_REG_ADC1_EQ5,
49148e27874SAdam Thomson DA732X_EQ_BAND5_SHIFT, DA732X_EQ_VOL_VAL_MAX,
49248e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
49348e27874SAdam Thomson SOC_SINGLE_TLV("ADC1 EQ Overall Volume", DA732X_REG_ADC1_EQ5,
49448e27874SAdam Thomson DA732X_EQ_OVERALL_SHIFT, DA732X_EQ_OVERALL_VOL_VAL_MAX,
49548e27874SAdam Thomson DA732X_INVERT, eq_overall_tlv),
49648e27874SAdam Thomson
49748e27874SAdam Thomson SOC_SINGLE("ADC2 EQ Switch", DA732X_REG_ADC2_EQ5,
49848e27874SAdam Thomson DA732X_EQ_EN_SHIFT, DA732X_EQ_EN_MAX, DA732X_NO_INVERT),
49948e27874SAdam Thomson SOC_SINGLE_TLV("ADC2 EQ Band 1 Volume", DA732X_REG_ADC2_EQ12,
50048e27874SAdam Thomson DA732X_EQ_BAND1_SHIFT, DA732X_EQ_VOL_VAL_MAX,
50148e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
50248e27874SAdam Thomson SOC_SINGLE_TLV("ADC2 EQ Band 2 Volume", DA732X_REG_ADC2_EQ12,
50348e27874SAdam Thomson DA732X_EQ_BAND2_SHIFT, DA732X_EQ_VOL_VAL_MAX,
50448e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
50548e27874SAdam Thomson SOC_SINGLE_TLV("ADC2 EQ Band 3 Volume", DA732X_REG_ADC2_EQ34,
50648e27874SAdam Thomson DA732X_EQ_BAND3_SHIFT, DA732X_EQ_VOL_VAL_MAX,
50748e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
50848e27874SAdam Thomson SOC_SINGLE_TLV("ACD2 EQ Band 4 Volume", DA732X_REG_ADC2_EQ34,
50948e27874SAdam Thomson DA732X_EQ_BAND4_SHIFT, DA732X_EQ_VOL_VAL_MAX,
51048e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
51148e27874SAdam Thomson SOC_SINGLE_TLV("ACD2 EQ Band 5 Volume", DA732X_REG_ADC2_EQ5,
51248e27874SAdam Thomson DA732X_EQ_BAND5_SHIFT, DA732X_EQ_VOL_VAL_MAX,
51348e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
51448e27874SAdam Thomson SOC_SINGLE_TLV("ADC2 EQ Overall Volume", DA732X_REG_ADC1_EQ5,
51548e27874SAdam Thomson DA732X_EQ_OVERALL_SHIFT, DA732X_EQ_OVERALL_VOL_VAL_MAX,
51648e27874SAdam Thomson DA732X_INVERT, eq_overall_tlv),
51748e27874SAdam Thomson
51848e27874SAdam Thomson SOC_SINGLE("DAC1 EQ Switch", DA732X_REG_DAC1_EQ5,
51948e27874SAdam Thomson DA732X_EQ_EN_SHIFT, DA732X_EQ_EN_MAX, DA732X_NO_INVERT),
52048e27874SAdam Thomson SOC_SINGLE_TLV("DAC1 EQ Band 1 Volume", DA732X_REG_DAC1_EQ12,
52148e27874SAdam Thomson DA732X_EQ_BAND1_SHIFT, DA732X_EQ_VOL_VAL_MAX,
52248e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
52348e27874SAdam Thomson SOC_SINGLE_TLV("DAC1 EQ Band 2 Volume", DA732X_REG_DAC1_EQ12,
52448e27874SAdam Thomson DA732X_EQ_BAND2_SHIFT, DA732X_EQ_VOL_VAL_MAX,
52548e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
52648e27874SAdam Thomson SOC_SINGLE_TLV("DAC1 EQ Band 3 Volume", DA732X_REG_DAC1_EQ34,
52748e27874SAdam Thomson DA732X_EQ_BAND3_SHIFT, DA732X_EQ_VOL_VAL_MAX,
52848e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
52948e27874SAdam Thomson SOC_SINGLE_TLV("DAC1 EQ Band 4 Volume", DA732X_REG_DAC1_EQ34,
53048e27874SAdam Thomson DA732X_EQ_BAND4_SHIFT, DA732X_EQ_VOL_VAL_MAX,
53148e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
53248e27874SAdam Thomson SOC_SINGLE_TLV("DAC1 EQ Band 5 Volume", DA732X_REG_DAC1_EQ5,
53348e27874SAdam Thomson DA732X_EQ_BAND5_SHIFT, DA732X_EQ_VOL_VAL_MAX,
53448e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
53548e27874SAdam Thomson
53648e27874SAdam Thomson SOC_SINGLE("DAC2 EQ Switch", DA732X_REG_DAC2_EQ5,
53748e27874SAdam Thomson DA732X_EQ_EN_SHIFT, DA732X_EQ_EN_MAX, DA732X_NO_INVERT),
53848e27874SAdam Thomson SOC_SINGLE_TLV("DAC2 EQ Band 1 Volume", DA732X_REG_DAC2_EQ12,
53948e27874SAdam Thomson DA732X_EQ_BAND1_SHIFT, DA732X_EQ_VOL_VAL_MAX,
54048e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
54148e27874SAdam Thomson SOC_SINGLE_TLV("DAC2 EQ Band 2 Volume", DA732X_REG_DAC2_EQ12,
54248e27874SAdam Thomson DA732X_EQ_BAND2_SHIFT, DA732X_EQ_VOL_VAL_MAX,
54348e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
54448e27874SAdam Thomson SOC_SINGLE_TLV("DAC2 EQ Band 3 Volume", DA732X_REG_DAC2_EQ34,
54548e27874SAdam Thomson DA732X_EQ_BAND3_SHIFT, DA732X_EQ_VOL_VAL_MAX,
54648e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
54748e27874SAdam Thomson SOC_SINGLE_TLV("DAC2 EQ Band 4 Volume", DA732X_REG_DAC2_EQ34,
54848e27874SAdam Thomson DA732X_EQ_BAND4_SHIFT, DA732X_EQ_VOL_VAL_MAX,
54948e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
55048e27874SAdam Thomson SOC_SINGLE_TLV("DAC2 EQ Band 5 Volume", DA732X_REG_DAC2_EQ5,
55148e27874SAdam Thomson DA732X_EQ_BAND5_SHIFT, DA732X_EQ_VOL_VAL_MAX,
55248e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
55348e27874SAdam Thomson
55448e27874SAdam Thomson SOC_SINGLE("DAC3 EQ Switch", DA732X_REG_DAC3_EQ5,
55548e27874SAdam Thomson DA732X_EQ_EN_SHIFT, DA732X_EQ_EN_MAX, DA732X_NO_INVERT),
55648e27874SAdam Thomson SOC_SINGLE_TLV("DAC3 EQ Band 1 Volume", DA732X_REG_DAC3_EQ12,
55748e27874SAdam Thomson DA732X_EQ_BAND1_SHIFT, DA732X_EQ_VOL_VAL_MAX,
55848e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
55948e27874SAdam Thomson SOC_SINGLE_TLV("DAC3 EQ Band 2 Volume", DA732X_REG_DAC3_EQ12,
56048e27874SAdam Thomson DA732X_EQ_BAND2_SHIFT, DA732X_EQ_VOL_VAL_MAX,
56148e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
56248e27874SAdam Thomson SOC_SINGLE_TLV("DAC3 EQ Band 3 Volume", DA732X_REG_DAC3_EQ34,
56348e27874SAdam Thomson DA732X_EQ_BAND3_SHIFT, DA732X_EQ_VOL_VAL_MAX,
56448e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
56548e27874SAdam Thomson SOC_SINGLE_TLV("DAC3 EQ Band 4 Volume", DA732X_REG_DAC3_EQ34,
56648e27874SAdam Thomson DA732X_EQ_BAND4_SHIFT, DA732X_EQ_VOL_VAL_MAX,
56748e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
56848e27874SAdam Thomson SOC_SINGLE_TLV("DAC3 EQ Band 5 Volume", DA732X_REG_DAC3_EQ5,
56948e27874SAdam Thomson DA732X_EQ_BAND5_SHIFT, DA732X_EQ_VOL_VAL_MAX,
57048e27874SAdam Thomson DA732X_INVERT, eq_band_pga_tlv),
57148e27874SAdam Thomson
57248e27874SAdam Thomson /* Lineout 2 Reciever*/
57348e27874SAdam Thomson SOC_SINGLE("Lineout 2 Switch", DA732X_REG_LIN2, DA732X_LOUT_MUTE_SHIFT,
57448e27874SAdam Thomson DA732X_SWITCH_MAX, DA732X_INVERT),
57548e27874SAdam Thomson SOC_SINGLE_TLV("Lineout 2 Volume", DA732X_REG_LIN2,
57648e27874SAdam Thomson DA732X_LOUT_VOL_SHIFT, DA732X_LOUT_VOL_VAL_MAX,
57748e27874SAdam Thomson DA732X_NO_INVERT, lin2_pga_tlv),
57848e27874SAdam Thomson
57948e27874SAdam Thomson /* Lineout 3 SPEAKER*/
58048e27874SAdam Thomson SOC_SINGLE("Lineout 3 Switch", DA732X_REG_LIN3, DA732X_LOUT_MUTE_SHIFT,
58148e27874SAdam Thomson DA732X_SWITCH_MAX, DA732X_INVERT),
58248e27874SAdam Thomson SOC_SINGLE_TLV("Lineout 3 Volume", DA732X_REG_LIN3,
58348e27874SAdam Thomson DA732X_LOUT_VOL_SHIFT, DA732X_LOUT_VOL_VAL_MAX,
58448e27874SAdam Thomson DA732X_NO_INVERT, lin3_pga_tlv),
58548e27874SAdam Thomson
58648e27874SAdam Thomson /* Lineout 4 */
58748e27874SAdam Thomson SOC_SINGLE("Lineout 4 Switch", DA732X_REG_LIN4, DA732X_LOUT_MUTE_SHIFT,
58848e27874SAdam Thomson DA732X_SWITCH_MAX, DA732X_INVERT),
58948e27874SAdam Thomson SOC_SINGLE_TLV("Lineout 4 Volume", DA732X_REG_LIN4,
59048e27874SAdam Thomson DA732X_LOUT_VOL_SHIFT, DA732X_LOUT_VOL_VAL_MAX,
59148e27874SAdam Thomson DA732X_NO_INVERT, lin4_pga_tlv),
59248e27874SAdam Thomson
59348e27874SAdam Thomson /* Headphones */
59448e27874SAdam Thomson SOC_DOUBLE_R("Headphone Switch", DA732X_REG_HPR, DA732X_REG_HPL,
59548e27874SAdam Thomson DA732X_HP_MUTE_SHIFT, DA732X_SWITCH_MAX, DA732X_INVERT),
59648e27874SAdam Thomson SOC_DOUBLE_R_TLV("Headphone Volume", DA732X_REG_HPL_VOL,
59748e27874SAdam Thomson DA732X_REG_HPR_VOL, DA732X_HP_VOL_SHIFT,
59848e27874SAdam Thomson DA732X_HP_VOL_VAL_MAX, DA732X_NO_INVERT, hp_pga_tlv),
59948e27874SAdam Thomson };
60048e27874SAdam Thomson
da732x_adc_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)60148e27874SAdam Thomson static int da732x_adc_event(struct snd_soc_dapm_widget *w,
60248e27874SAdam Thomson struct snd_kcontrol *kcontrol, int event)
60348e27874SAdam Thomson {
604192ce2fbSKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
60548e27874SAdam Thomson
60648e27874SAdam Thomson switch (event) {
60748e27874SAdam Thomson case SND_SOC_DAPM_POST_PMU:
60848e27874SAdam Thomson switch (w->reg) {
60948e27874SAdam Thomson case DA732X_REG_ADC1_PD:
610192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_CLK_EN3,
61148e27874SAdam Thomson DA732X_ADCA_BB_CLK_EN,
61248e27874SAdam Thomson DA732X_ADCA_BB_CLK_EN);
61348e27874SAdam Thomson break;
61448e27874SAdam Thomson case DA732X_REG_ADC2_PD:
615192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_CLK_EN3,
61648e27874SAdam Thomson DA732X_ADCC_BB_CLK_EN,
61748e27874SAdam Thomson DA732X_ADCC_BB_CLK_EN);
61848e27874SAdam Thomson break;
61948e27874SAdam Thomson default:
62048e27874SAdam Thomson return -EINVAL;
62148e27874SAdam Thomson }
62248e27874SAdam Thomson
623192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, w->reg, DA732X_ADC_RST_MASK,
62448e27874SAdam Thomson DA732X_ADC_SET_ACT);
625192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, w->reg, DA732X_ADC_PD_MASK,
62648e27874SAdam Thomson DA732X_ADC_ON);
62748e27874SAdam Thomson break;
62848e27874SAdam Thomson case SND_SOC_DAPM_POST_PMD:
629192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, w->reg, DA732X_ADC_PD_MASK,
63048e27874SAdam Thomson DA732X_ADC_OFF);
631192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, w->reg, DA732X_ADC_RST_MASK,
63248e27874SAdam Thomson DA732X_ADC_SET_RST);
63348e27874SAdam Thomson
63448e27874SAdam Thomson switch (w->reg) {
63548e27874SAdam Thomson case DA732X_REG_ADC1_PD:
636192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_CLK_EN3,
63748e27874SAdam Thomson DA732X_ADCA_BB_CLK_EN, 0);
63848e27874SAdam Thomson break;
63948e27874SAdam Thomson case DA732X_REG_ADC2_PD:
640192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_CLK_EN3,
64148e27874SAdam Thomson DA732X_ADCC_BB_CLK_EN, 0);
64248e27874SAdam Thomson break;
64348e27874SAdam Thomson default:
64448e27874SAdam Thomson return -EINVAL;
64548e27874SAdam Thomson }
64648e27874SAdam Thomson
64748e27874SAdam Thomson break;
64848e27874SAdam Thomson default:
64948e27874SAdam Thomson return -EINVAL;
65048e27874SAdam Thomson }
65148e27874SAdam Thomson
65248e27874SAdam Thomson return 0;
65348e27874SAdam Thomson }
65448e27874SAdam Thomson
da732x_out_pga_event(struct snd_soc_dapm_widget * w,struct snd_kcontrol * kcontrol,int event)65548e27874SAdam Thomson static int da732x_out_pga_event(struct snd_soc_dapm_widget *w,
65648e27874SAdam Thomson struct snd_kcontrol *kcontrol, int event)
65748e27874SAdam Thomson {
658192ce2fbSKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
65948e27874SAdam Thomson
66048e27874SAdam Thomson switch (event) {
66148e27874SAdam Thomson case SND_SOC_DAPM_POST_PMU:
662192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, w->reg,
66348e27874SAdam Thomson (1 << w->shift) | DA732X_OUT_HIZ_EN,
66448e27874SAdam Thomson (1 << w->shift) | DA732X_OUT_HIZ_EN);
66548e27874SAdam Thomson break;
66648e27874SAdam Thomson case SND_SOC_DAPM_POST_PMD:
667192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, w->reg,
66848e27874SAdam Thomson (1 << w->shift) | DA732X_OUT_HIZ_EN,
66948e27874SAdam Thomson (1 << w->shift) | DA732X_OUT_HIZ_DIS);
67048e27874SAdam Thomson break;
67148e27874SAdam Thomson default:
67248e27874SAdam Thomson return -EINVAL;
67348e27874SAdam Thomson }
67448e27874SAdam Thomson
67548e27874SAdam Thomson return 0;
67648e27874SAdam Thomson }
67748e27874SAdam Thomson
67848e27874SAdam Thomson static const char *adcl_text[] = {
67948e27874SAdam Thomson "AUX1L", "MIC1"
68048e27874SAdam Thomson };
68148e27874SAdam Thomson
68248e27874SAdam Thomson static const char *adcr_text[] = {
68348e27874SAdam Thomson "AUX1R", "MIC2", "MIC3"
68448e27874SAdam Thomson };
68548e27874SAdam Thomson
68648e27874SAdam Thomson static const char *enable_text[] = {
68748e27874SAdam Thomson "Disabled",
68848e27874SAdam Thomson "Enabled"
68948e27874SAdam Thomson };
69048e27874SAdam Thomson
69148e27874SAdam Thomson /* ADC1LMUX */
6927e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(adc1l_enum,
6937e509108STakashi Iwai DA732X_REG_INP_MUX, DA732X_ADC1L_MUX_SEL_SHIFT,
6947e509108STakashi Iwai adcl_text);
69548e27874SAdam Thomson static const struct snd_kcontrol_new adc1l_mux =
69648e27874SAdam Thomson SOC_DAPM_ENUM("ADC Route", adc1l_enum);
69748e27874SAdam Thomson
69848e27874SAdam Thomson /* ADC1RMUX */
6997e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(adc1r_enum,
7007e509108STakashi Iwai DA732X_REG_INP_MUX, DA732X_ADC1R_MUX_SEL_SHIFT,
7017e509108STakashi Iwai adcr_text);
70248e27874SAdam Thomson static const struct snd_kcontrol_new adc1r_mux =
70348e27874SAdam Thomson SOC_DAPM_ENUM("ADC Route", adc1r_enum);
70448e27874SAdam Thomson
70548e27874SAdam Thomson /* ADC2LMUX */
7067e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(adc2l_enum,
7077e509108STakashi Iwai DA732X_REG_INP_MUX, DA732X_ADC2L_MUX_SEL_SHIFT,
7087e509108STakashi Iwai adcl_text);
70948e27874SAdam Thomson static const struct snd_kcontrol_new adc2l_mux =
71048e27874SAdam Thomson SOC_DAPM_ENUM("ADC Route", adc2l_enum);
71148e27874SAdam Thomson
71248e27874SAdam Thomson /* ADC2RMUX */
7137e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(adc2r_enum,
7147e509108STakashi Iwai DA732X_REG_INP_MUX, DA732X_ADC2R_MUX_SEL_SHIFT,
7157e509108STakashi Iwai adcr_text);
71648e27874SAdam Thomson
71748e27874SAdam Thomson static const struct snd_kcontrol_new adc2r_mux =
71848e27874SAdam Thomson SOC_DAPM_ENUM("ADC Route", adc2r_enum);
71948e27874SAdam Thomson
7207e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_hp_left_output,
7217e509108STakashi Iwai DA732X_REG_HPL, DA732X_HP_OUT_DAC_EN_SHIFT,
7227e509108STakashi Iwai enable_text);
72348e27874SAdam Thomson
72448e27874SAdam Thomson static const struct snd_kcontrol_new hpl_mux =
72548e27874SAdam Thomson SOC_DAPM_ENUM("HPL Switch", da732x_hp_left_output);
72648e27874SAdam Thomson
7277e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_hp_right_output,
7287e509108STakashi Iwai DA732X_REG_HPR, DA732X_HP_OUT_DAC_EN_SHIFT,
7297e509108STakashi Iwai enable_text);
73048e27874SAdam Thomson
73148e27874SAdam Thomson static const struct snd_kcontrol_new hpr_mux =
73248e27874SAdam Thomson SOC_DAPM_ENUM("HPR Switch", da732x_hp_right_output);
73348e27874SAdam Thomson
7347e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_speaker_output,
7357e509108STakashi Iwai DA732X_REG_LIN3, DA732X_LOUT_DAC_EN_SHIFT,
7367e509108STakashi Iwai enable_text);
73748e27874SAdam Thomson
73848e27874SAdam Thomson static const struct snd_kcontrol_new spk_mux =
73948e27874SAdam Thomson SOC_DAPM_ENUM("SPK Switch", da732x_speaker_output);
74048e27874SAdam Thomson
7417e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_lout4_output,
7427e509108STakashi Iwai DA732X_REG_LIN4, DA732X_LOUT_DAC_EN_SHIFT,
7437e509108STakashi Iwai enable_text);
74448e27874SAdam Thomson
74548e27874SAdam Thomson static const struct snd_kcontrol_new lout4_mux =
74648e27874SAdam Thomson SOC_DAPM_ENUM("LOUT4 Switch", da732x_lout4_output);
74748e27874SAdam Thomson
7487e509108STakashi Iwai static SOC_ENUM_SINGLE_DECL(da732x_lout2_output,
7497e509108STakashi Iwai DA732X_REG_LIN2, DA732X_LOUT_DAC_EN_SHIFT,
7507e509108STakashi Iwai enable_text);
75148e27874SAdam Thomson
75248e27874SAdam Thomson static const struct snd_kcontrol_new lout2_mux =
75348e27874SAdam Thomson SOC_DAPM_ENUM("LOUT2 Switch", da732x_lout2_output);
75448e27874SAdam Thomson
75548e27874SAdam Thomson static const struct snd_soc_dapm_widget da732x_dapm_widgets[] = {
75648e27874SAdam Thomson /* Supplies */
75748e27874SAdam Thomson SND_SOC_DAPM_SUPPLY("ADC1 Supply", DA732X_REG_ADC1_PD, 0,
75848e27874SAdam Thomson DA732X_NO_INVERT, da732x_adc_event,
75948e27874SAdam Thomson SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
76048e27874SAdam Thomson SND_SOC_DAPM_SUPPLY("ADC2 Supply", DA732X_REG_ADC2_PD, 0,
76148e27874SAdam Thomson DA732X_NO_INVERT, da732x_adc_event,
76248e27874SAdam Thomson SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
76348e27874SAdam Thomson SND_SOC_DAPM_SUPPLY("DAC1 CLK", DA732X_REG_CLK_EN4,
76448e27874SAdam Thomson DA732X_DACA_BB_CLK_SHIFT, DA732X_NO_INVERT,
76548e27874SAdam Thomson NULL, 0),
76648e27874SAdam Thomson SND_SOC_DAPM_SUPPLY("DAC2 CLK", DA732X_REG_CLK_EN4,
76748e27874SAdam Thomson DA732X_DACC_BB_CLK_SHIFT, DA732X_NO_INVERT,
76848e27874SAdam Thomson NULL, 0),
76948e27874SAdam Thomson SND_SOC_DAPM_SUPPLY("DAC3 CLK", DA732X_REG_CLK_EN5,
77048e27874SAdam Thomson DA732X_DACE_BB_CLK_SHIFT, DA732X_NO_INVERT,
77148e27874SAdam Thomson NULL, 0),
77248e27874SAdam Thomson
77348e27874SAdam Thomson /* Micbias */
77448e27874SAdam Thomson SND_SOC_DAPM_SUPPLY("MICBIAS1", DA732X_REG_MICBIAS1,
77548e27874SAdam Thomson DA732X_MICBIAS_EN_SHIFT,
77648e27874SAdam Thomson DA732X_NO_INVERT, NULL, 0),
77748e27874SAdam Thomson SND_SOC_DAPM_SUPPLY("MICBIAS2", DA732X_REG_MICBIAS2,
77848e27874SAdam Thomson DA732X_MICBIAS_EN_SHIFT,
77948e27874SAdam Thomson DA732X_NO_INVERT, NULL, 0),
78048e27874SAdam Thomson
78148e27874SAdam Thomson /* Inputs */
78248e27874SAdam Thomson SND_SOC_DAPM_INPUT("MIC1"),
78348e27874SAdam Thomson SND_SOC_DAPM_INPUT("MIC2"),
78448e27874SAdam Thomson SND_SOC_DAPM_INPUT("MIC3"),
78548e27874SAdam Thomson SND_SOC_DAPM_INPUT("AUX1L"),
78648e27874SAdam Thomson SND_SOC_DAPM_INPUT("AUX1R"),
78748e27874SAdam Thomson
78848e27874SAdam Thomson /* Outputs */
78948e27874SAdam Thomson SND_SOC_DAPM_OUTPUT("HPL"),
79048e27874SAdam Thomson SND_SOC_DAPM_OUTPUT("HPR"),
79148e27874SAdam Thomson SND_SOC_DAPM_OUTPUT("LOUTL"),
79248e27874SAdam Thomson SND_SOC_DAPM_OUTPUT("LOUTR"),
79348e27874SAdam Thomson SND_SOC_DAPM_OUTPUT("ClassD"),
79448e27874SAdam Thomson
79548e27874SAdam Thomson /* ADCs */
79648e27874SAdam Thomson SND_SOC_DAPM_ADC("ADC1L", NULL, DA732X_REG_ADC1_SEL,
79748e27874SAdam Thomson DA732X_ADCL_EN_SHIFT, DA732X_NO_INVERT),
79848e27874SAdam Thomson SND_SOC_DAPM_ADC("ADC1R", NULL, DA732X_REG_ADC1_SEL,
79948e27874SAdam Thomson DA732X_ADCR_EN_SHIFT, DA732X_NO_INVERT),
80048e27874SAdam Thomson SND_SOC_DAPM_ADC("ADC2L", NULL, DA732X_REG_ADC2_SEL,
80148e27874SAdam Thomson DA732X_ADCL_EN_SHIFT, DA732X_NO_INVERT),
80248e27874SAdam Thomson SND_SOC_DAPM_ADC("ADC2R", NULL, DA732X_REG_ADC2_SEL,
80348e27874SAdam Thomson DA732X_ADCR_EN_SHIFT, DA732X_NO_INVERT),
80448e27874SAdam Thomson
80548e27874SAdam Thomson /* DACs */
80648e27874SAdam Thomson SND_SOC_DAPM_DAC("DAC1L", NULL, DA732X_REG_DAC1_SEL,
80748e27874SAdam Thomson DA732X_DACL_EN_SHIFT, DA732X_NO_INVERT),
80848e27874SAdam Thomson SND_SOC_DAPM_DAC("DAC1R", NULL, DA732X_REG_DAC1_SEL,
80948e27874SAdam Thomson DA732X_DACR_EN_SHIFT, DA732X_NO_INVERT),
81048e27874SAdam Thomson SND_SOC_DAPM_DAC("DAC2L", NULL, DA732X_REG_DAC2_SEL,
81148e27874SAdam Thomson DA732X_DACL_EN_SHIFT, DA732X_NO_INVERT),
81248e27874SAdam Thomson SND_SOC_DAPM_DAC("DAC2R", NULL, DA732X_REG_DAC2_SEL,
81348e27874SAdam Thomson DA732X_DACR_EN_SHIFT, DA732X_NO_INVERT),
81448e27874SAdam Thomson SND_SOC_DAPM_DAC("DAC3", NULL, DA732X_REG_DAC3_SEL,
81548e27874SAdam Thomson DA732X_DACL_EN_SHIFT, DA732X_NO_INVERT),
81648e27874SAdam Thomson
81748e27874SAdam Thomson /* Input Pgas */
81848e27874SAdam Thomson SND_SOC_DAPM_PGA("MIC1 PGA", DA732X_REG_MIC1, DA732X_MIC_EN_SHIFT,
81948e27874SAdam Thomson 0, NULL, 0),
82048e27874SAdam Thomson SND_SOC_DAPM_PGA("MIC2 PGA", DA732X_REG_MIC2, DA732X_MIC_EN_SHIFT,
82148e27874SAdam Thomson 0, NULL, 0),
82248e27874SAdam Thomson SND_SOC_DAPM_PGA("MIC3 PGA", DA732X_REG_MIC3, DA732X_MIC_EN_SHIFT,
82348e27874SAdam Thomson 0, NULL, 0),
82448e27874SAdam Thomson SND_SOC_DAPM_PGA("AUX1L PGA", DA732X_REG_AUX1L, DA732X_AUX_EN_SHIFT,
82548e27874SAdam Thomson 0, NULL, 0),
82648e27874SAdam Thomson SND_SOC_DAPM_PGA("AUX1R PGA", DA732X_REG_AUX1R, DA732X_AUX_EN_SHIFT,
82748e27874SAdam Thomson 0, NULL, 0),
82848e27874SAdam Thomson
82948e27874SAdam Thomson SND_SOC_DAPM_PGA_E("HP Left", DA732X_REG_HPL, DA732X_HP_OUT_EN_SHIFT,
83048e27874SAdam Thomson 0, NULL, 0, da732x_out_pga_event,
83148e27874SAdam Thomson SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
83248e27874SAdam Thomson SND_SOC_DAPM_PGA_E("HP Right", DA732X_REG_HPR, DA732X_HP_OUT_EN_SHIFT,
83348e27874SAdam Thomson 0, NULL, 0, da732x_out_pga_event,
83448e27874SAdam Thomson SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
83548e27874SAdam Thomson SND_SOC_DAPM_PGA_E("LIN2", DA732X_REG_LIN2, DA732X_LIN_OUT_EN_SHIFT,
83648e27874SAdam Thomson 0, NULL, 0, da732x_out_pga_event,
83748e27874SAdam Thomson SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
83848e27874SAdam Thomson SND_SOC_DAPM_PGA_E("LIN3", DA732X_REG_LIN3, DA732X_LIN_OUT_EN_SHIFT,
83948e27874SAdam Thomson 0, NULL, 0, da732x_out_pga_event,
84048e27874SAdam Thomson SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
84148e27874SAdam Thomson SND_SOC_DAPM_PGA_E("LIN4", DA732X_REG_LIN4, DA732X_LIN_OUT_EN_SHIFT,
84248e27874SAdam Thomson 0, NULL, 0, da732x_out_pga_event,
84348e27874SAdam Thomson SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
84448e27874SAdam Thomson
84548e27874SAdam Thomson /* MUXs */
84648e27874SAdam Thomson SND_SOC_DAPM_MUX("ADC1 Left MUX", SND_SOC_NOPM, 0, 0, &adc1l_mux),
84748e27874SAdam Thomson SND_SOC_DAPM_MUX("ADC1 Right MUX", SND_SOC_NOPM, 0, 0, &adc1r_mux),
84848e27874SAdam Thomson SND_SOC_DAPM_MUX("ADC2 Left MUX", SND_SOC_NOPM, 0, 0, &adc2l_mux),
84948e27874SAdam Thomson SND_SOC_DAPM_MUX("ADC2 Right MUX", SND_SOC_NOPM, 0, 0, &adc2r_mux),
85048e27874SAdam Thomson
85148e27874SAdam Thomson SND_SOC_DAPM_MUX("HP Left MUX", SND_SOC_NOPM, 0, 0, &hpl_mux),
85248e27874SAdam Thomson SND_SOC_DAPM_MUX("HP Right MUX", SND_SOC_NOPM, 0, 0, &hpr_mux),
85348e27874SAdam Thomson SND_SOC_DAPM_MUX("Speaker MUX", SND_SOC_NOPM, 0, 0, &spk_mux),
85448e27874SAdam Thomson SND_SOC_DAPM_MUX("LOUT2 MUX", SND_SOC_NOPM, 0, 0, &lout2_mux),
85548e27874SAdam Thomson SND_SOC_DAPM_MUX("LOUT4 MUX", SND_SOC_NOPM, 0, 0, &lout4_mux),
85648e27874SAdam Thomson
85748e27874SAdam Thomson /* AIF interfaces */
85848e27874SAdam Thomson SND_SOC_DAPM_AIF_OUT("AIFA Output", "AIFA Capture", 0, DA732X_REG_AIFA3,
85948e27874SAdam Thomson DA732X_AIF_EN_SHIFT, 0),
86048e27874SAdam Thomson SND_SOC_DAPM_AIF_IN("AIFA Input", "AIFA Playback", 0, DA732X_REG_AIFA3,
86148e27874SAdam Thomson DA732X_AIF_EN_SHIFT, 0),
86248e27874SAdam Thomson
86348e27874SAdam Thomson SND_SOC_DAPM_AIF_OUT("AIFB Output", "AIFB Capture", 0, DA732X_REG_AIFB3,
86448e27874SAdam Thomson DA732X_AIF_EN_SHIFT, 0),
86548e27874SAdam Thomson SND_SOC_DAPM_AIF_IN("AIFB Input", "AIFB Playback", 0, DA732X_REG_AIFB3,
86648e27874SAdam Thomson DA732X_AIF_EN_SHIFT, 0),
86748e27874SAdam Thomson };
86848e27874SAdam Thomson
86948e27874SAdam Thomson static const struct snd_soc_dapm_route da732x_dapm_routes[] = {
87048e27874SAdam Thomson /* Inputs */
8718e6a75c1SLars-Peter Clausen {"AUX1L PGA", NULL, "AUX1L"},
8728e6a75c1SLars-Peter Clausen {"AUX1R PGA", NULL, "AUX1R"},
87348e27874SAdam Thomson {"MIC1 PGA", NULL, "MIC1"},
8748e6a75c1SLars-Peter Clausen {"MIC2 PGA", NULL, "MIC2"},
8758e6a75c1SLars-Peter Clausen {"MIC3 PGA", NULL, "MIC3"},
87648e27874SAdam Thomson
87748e27874SAdam Thomson /* Capture Path */
87848e27874SAdam Thomson {"ADC1 Left MUX", "MIC1", "MIC1 PGA"},
87948e27874SAdam Thomson {"ADC1 Left MUX", "AUX1L", "AUX1L PGA"},
88048e27874SAdam Thomson
88148e27874SAdam Thomson {"ADC1 Right MUX", "AUX1R", "AUX1R PGA"},
88248e27874SAdam Thomson {"ADC1 Right MUX", "MIC2", "MIC2 PGA"},
88348e27874SAdam Thomson {"ADC1 Right MUX", "MIC3", "MIC3 PGA"},
88448e27874SAdam Thomson
88548e27874SAdam Thomson {"ADC2 Left MUX", "AUX1L", "AUX1L PGA"},
88648e27874SAdam Thomson {"ADC2 Left MUX", "MIC1", "MIC1 PGA"},
88748e27874SAdam Thomson
88848e27874SAdam Thomson {"ADC2 Right MUX", "AUX1R", "AUX1R PGA"},
88948e27874SAdam Thomson {"ADC2 Right MUX", "MIC2", "MIC2 PGA"},
89048e27874SAdam Thomson {"ADC2 Right MUX", "MIC3", "MIC3 PGA"},
89148e27874SAdam Thomson
89248e27874SAdam Thomson {"ADC1L", NULL, "ADC1 Supply"},
89348e27874SAdam Thomson {"ADC1R", NULL, "ADC1 Supply"},
89448e27874SAdam Thomson {"ADC2L", NULL, "ADC2 Supply"},
89548e27874SAdam Thomson {"ADC2R", NULL, "ADC2 Supply"},
89648e27874SAdam Thomson
89748e27874SAdam Thomson {"ADC1L", NULL, "ADC1 Left MUX"},
89848e27874SAdam Thomson {"ADC1R", NULL, "ADC1 Right MUX"},
89948e27874SAdam Thomson {"ADC2L", NULL, "ADC2 Left MUX"},
90048e27874SAdam Thomson {"ADC2R", NULL, "ADC2 Right MUX"},
90148e27874SAdam Thomson
90248e27874SAdam Thomson {"AIFA Output", NULL, "ADC1L"},
90348e27874SAdam Thomson {"AIFA Output", NULL, "ADC1R"},
90448e27874SAdam Thomson {"AIFB Output", NULL, "ADC2L"},
90548e27874SAdam Thomson {"AIFB Output", NULL, "ADC2R"},
90648e27874SAdam Thomson
90748e27874SAdam Thomson {"HP Left MUX", "Enabled", "AIFA Input"},
90848e27874SAdam Thomson {"HP Right MUX", "Enabled", "AIFA Input"},
90948e27874SAdam Thomson {"Speaker MUX", "Enabled", "AIFB Input"},
91048e27874SAdam Thomson {"LOUT2 MUX", "Enabled", "AIFB Input"},
91148e27874SAdam Thomson {"LOUT4 MUX", "Enabled", "AIFB Input"},
91248e27874SAdam Thomson
91348e27874SAdam Thomson {"DAC1L", NULL, "DAC1 CLK"},
91448e27874SAdam Thomson {"DAC1R", NULL, "DAC1 CLK"},
91548e27874SAdam Thomson {"DAC2L", NULL, "DAC2 CLK"},
91648e27874SAdam Thomson {"DAC2R", NULL, "DAC2 CLK"},
91748e27874SAdam Thomson {"DAC3", NULL, "DAC3 CLK"},
91848e27874SAdam Thomson
91948e27874SAdam Thomson {"DAC1L", NULL, "HP Left MUX"},
92048e27874SAdam Thomson {"DAC1R", NULL, "HP Right MUX"},
92148e27874SAdam Thomson {"DAC2L", NULL, "Speaker MUX"},
92248e27874SAdam Thomson {"DAC2R", NULL, "LOUT4 MUX"},
92348e27874SAdam Thomson {"DAC3", NULL, "LOUT2 MUX"},
92448e27874SAdam Thomson
92548e27874SAdam Thomson /* Output Pgas */
92648e27874SAdam Thomson {"HP Left", NULL, "DAC1L"},
92748e27874SAdam Thomson {"HP Right", NULL, "DAC1R"},
92848e27874SAdam Thomson {"LIN3", NULL, "DAC2L"},
92948e27874SAdam Thomson {"LIN4", NULL, "DAC2R"},
93048e27874SAdam Thomson {"LIN2", NULL, "DAC3"},
93148e27874SAdam Thomson
93248e27874SAdam Thomson /* Outputs */
93348e27874SAdam Thomson {"ClassD", NULL, "LIN3"},
93448e27874SAdam Thomson {"LOUTL", NULL, "LIN2"},
93548e27874SAdam Thomson {"LOUTR", NULL, "LIN4"},
93648e27874SAdam Thomson {"HPL", NULL, "HP Left"},
93748e27874SAdam Thomson {"HPR", NULL, "HP Right"},
93848e27874SAdam Thomson };
93948e27874SAdam Thomson
da732x_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)94048e27874SAdam Thomson static int da732x_hw_params(struct snd_pcm_substream *substream,
94148e27874SAdam Thomson struct snd_pcm_hw_params *params,
94248e27874SAdam Thomson struct snd_soc_dai *dai)
94348e27874SAdam Thomson {
944192ce2fbSKuninori Morimoto struct snd_soc_component *component = dai->component;
94548e27874SAdam Thomson u32 aif = 0;
94648e27874SAdam Thomson u32 reg_aif;
94748e27874SAdam Thomson u32 fs;
94848e27874SAdam Thomson
94948e27874SAdam Thomson reg_aif = dai->driver->base;
95048e27874SAdam Thomson
951abf82ae6SMark Brown switch (params_width(params)) {
952abf82ae6SMark Brown case 16:
95348e27874SAdam Thomson aif |= DA732X_AIF_WORD_16;
95448e27874SAdam Thomson break;
955abf82ae6SMark Brown case 20:
95648e27874SAdam Thomson aif |= DA732X_AIF_WORD_20;
95748e27874SAdam Thomson break;
958abf82ae6SMark Brown case 24:
95948e27874SAdam Thomson aif |= DA732X_AIF_WORD_24;
96048e27874SAdam Thomson break;
961abf82ae6SMark Brown case 32:
96248e27874SAdam Thomson aif |= DA732X_AIF_WORD_32;
96348e27874SAdam Thomson break;
96448e27874SAdam Thomson default:
96548e27874SAdam Thomson return -EINVAL;
96648e27874SAdam Thomson }
96748e27874SAdam Thomson
96848e27874SAdam Thomson switch (params_rate(params)) {
96948e27874SAdam Thomson case 8000:
97048e27874SAdam Thomson fs = DA732X_SR_8KHZ;
97148e27874SAdam Thomson break;
97248e27874SAdam Thomson case 11025:
97348e27874SAdam Thomson fs = DA732X_SR_11_025KHZ;
97448e27874SAdam Thomson break;
97548e27874SAdam Thomson case 12000:
97648e27874SAdam Thomson fs = DA732X_SR_12KHZ;
97748e27874SAdam Thomson break;
97848e27874SAdam Thomson case 16000:
97948e27874SAdam Thomson fs = DA732X_SR_16KHZ;
98048e27874SAdam Thomson break;
98148e27874SAdam Thomson case 22050:
98248e27874SAdam Thomson fs = DA732X_SR_22_05KHZ;
98348e27874SAdam Thomson break;
98448e27874SAdam Thomson case 24000:
98548e27874SAdam Thomson fs = DA732X_SR_24KHZ;
98648e27874SAdam Thomson break;
98748e27874SAdam Thomson case 32000:
98848e27874SAdam Thomson fs = DA732X_SR_32KHZ;
98948e27874SAdam Thomson break;
99048e27874SAdam Thomson case 44100:
99148e27874SAdam Thomson fs = DA732X_SR_44_1KHZ;
99248e27874SAdam Thomson break;
99348e27874SAdam Thomson case 48000:
99448e27874SAdam Thomson fs = DA732X_SR_48KHZ;
99548e27874SAdam Thomson break;
99648e27874SAdam Thomson case 88100:
99748e27874SAdam Thomson fs = DA732X_SR_88_1KHZ;
99848e27874SAdam Thomson break;
99948e27874SAdam Thomson case 96000:
100048e27874SAdam Thomson fs = DA732X_SR_96KHZ;
100148e27874SAdam Thomson break;
100248e27874SAdam Thomson default:
100348e27874SAdam Thomson return -EINVAL;
100448e27874SAdam Thomson }
100548e27874SAdam Thomson
1006192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, reg_aif, DA732X_AIF_WORD_MASK, aif);
1007192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_CLK_CTRL, DA732X_SR1_MASK, fs);
100848e27874SAdam Thomson
100948e27874SAdam Thomson return 0;
101048e27874SAdam Thomson }
101148e27874SAdam Thomson
da732x_set_dai_fmt(struct snd_soc_dai * dai,u32 fmt)101248e27874SAdam Thomson static int da732x_set_dai_fmt(struct snd_soc_dai *dai, u32 fmt)
101348e27874SAdam Thomson {
1014192ce2fbSKuninori Morimoto struct snd_soc_component *component = dai->component;
101548e27874SAdam Thomson u32 aif_mclk, pc_count;
101648e27874SAdam Thomson u32 reg_aif1, aif1;
101748e27874SAdam Thomson u32 reg_aif3, aif3;
101848e27874SAdam Thomson
101948e27874SAdam Thomson switch (dai->id) {
102048e27874SAdam Thomson case DA732X_DAI_ID1:
102148e27874SAdam Thomson reg_aif1 = DA732X_REG_AIFA1;
102248e27874SAdam Thomson reg_aif3 = DA732X_REG_AIFA3;
102348e27874SAdam Thomson pc_count = DA732X_PC_PULSE_AIFA | DA732X_PC_RESYNC_NOT_AUT |
102448e27874SAdam Thomson DA732X_PC_SAME;
102548e27874SAdam Thomson break;
102648e27874SAdam Thomson case DA732X_DAI_ID2:
102748e27874SAdam Thomson reg_aif1 = DA732X_REG_AIFB1;
102848e27874SAdam Thomson reg_aif3 = DA732X_REG_AIFB3;
102948e27874SAdam Thomson pc_count = DA732X_PC_PULSE_AIFB | DA732X_PC_RESYNC_NOT_AUT |
103048e27874SAdam Thomson DA732X_PC_SAME;
103148e27874SAdam Thomson break;
103248e27874SAdam Thomson default:
103348e27874SAdam Thomson return -EINVAL;
103448e27874SAdam Thomson }
103548e27874SAdam Thomson
103648e27874SAdam Thomson switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
103748e27874SAdam Thomson case SND_SOC_DAIFMT_CBS_CFS:
103848e27874SAdam Thomson aif1 = DA732X_AIF_SLAVE;
103948e27874SAdam Thomson aif_mclk = DA732X_AIFM_FRAME_64 | DA732X_AIFM_SRC_SEL_AIFA;
104048e27874SAdam Thomson break;
104148e27874SAdam Thomson case SND_SOC_DAIFMT_CBM_CFM:
104248e27874SAdam Thomson aif1 = DA732X_AIF_CLK_FROM_SRC;
104348e27874SAdam Thomson aif_mclk = DA732X_CLK_GENERATION_AIF_A;
104448e27874SAdam Thomson break;
104548e27874SAdam Thomson default:
104648e27874SAdam Thomson return -EINVAL;
104748e27874SAdam Thomson }
104848e27874SAdam Thomson
104948e27874SAdam Thomson switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
105048e27874SAdam Thomson case SND_SOC_DAIFMT_I2S:
105148e27874SAdam Thomson aif3 = DA732X_AIF_I2S_MODE;
105248e27874SAdam Thomson break;
105348e27874SAdam Thomson case SND_SOC_DAIFMT_RIGHT_J:
105448e27874SAdam Thomson aif3 = DA732X_AIF_RIGHT_J_MODE;
105548e27874SAdam Thomson break;
105648e27874SAdam Thomson case SND_SOC_DAIFMT_LEFT_J:
105748e27874SAdam Thomson aif3 = DA732X_AIF_LEFT_J_MODE;
105848e27874SAdam Thomson break;
105948e27874SAdam Thomson case SND_SOC_DAIFMT_DSP_B:
106048e27874SAdam Thomson aif3 = DA732X_AIF_DSP_MODE;
106148e27874SAdam Thomson break;
106248e27874SAdam Thomson default:
106348e27874SAdam Thomson return -EINVAL;
106448e27874SAdam Thomson }
106548e27874SAdam Thomson
106648e27874SAdam Thomson /* Clock inversion */
106748e27874SAdam Thomson switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
106848e27874SAdam Thomson case SND_SOC_DAIFMT_DSP_B:
106948e27874SAdam Thomson switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
107048e27874SAdam Thomson case SND_SOC_DAIFMT_NB_NF:
107148e27874SAdam Thomson break;
107248e27874SAdam Thomson case SND_SOC_DAIFMT_IB_NF:
107348e27874SAdam Thomson aif3 |= DA732X_AIF_BCLK_INV;
107448e27874SAdam Thomson break;
107548e27874SAdam Thomson default:
107648e27874SAdam Thomson return -EINVAL;
107748e27874SAdam Thomson }
107848e27874SAdam Thomson break;
107948e27874SAdam Thomson case SND_SOC_DAIFMT_I2S:
108048e27874SAdam Thomson case SND_SOC_DAIFMT_RIGHT_J:
108148e27874SAdam Thomson case SND_SOC_DAIFMT_LEFT_J:
108248e27874SAdam Thomson switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
108348e27874SAdam Thomson case SND_SOC_DAIFMT_NB_NF:
108448e27874SAdam Thomson break;
108548e27874SAdam Thomson case SND_SOC_DAIFMT_IB_IF:
108648e27874SAdam Thomson aif3 |= DA732X_AIF_BCLK_INV | DA732X_AIF_WCLK_INV;
108748e27874SAdam Thomson break;
108848e27874SAdam Thomson case SND_SOC_DAIFMT_IB_NF:
108948e27874SAdam Thomson aif3 |= DA732X_AIF_BCLK_INV;
109048e27874SAdam Thomson break;
109148e27874SAdam Thomson case SND_SOC_DAIFMT_NB_IF:
109248e27874SAdam Thomson aif3 |= DA732X_AIF_WCLK_INV;
109348e27874SAdam Thomson break;
109448e27874SAdam Thomson default:
109548e27874SAdam Thomson return -EINVAL;
109648e27874SAdam Thomson }
109748e27874SAdam Thomson break;
109848e27874SAdam Thomson default:
109948e27874SAdam Thomson return -EINVAL;
110048e27874SAdam Thomson }
110148e27874SAdam Thomson
1102192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_AIF_MCLK, aif_mclk);
1103192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, reg_aif1, DA732X_AIF1_CLK_MASK, aif1);
1104192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, reg_aif3, DA732X_AIF_BCLK_INV |
110548e27874SAdam Thomson DA732X_AIF_WCLK_INV | DA732X_AIF_MODE_MASK, aif3);
1106192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_PC_CTRL, pc_count);
110748e27874SAdam Thomson
110848e27874SAdam Thomson return 0;
110948e27874SAdam Thomson }
111048e27874SAdam Thomson
111148e27874SAdam Thomson
111248e27874SAdam Thomson
da732x_set_dai_pll(struct snd_soc_component * component,int pll_id,int source,unsigned int freq_in,unsigned int freq_out)1113192ce2fbSKuninori Morimoto static int da732x_set_dai_pll(struct snd_soc_component *component, int pll_id,
111448e27874SAdam Thomson int source, unsigned int freq_in,
111548e27874SAdam Thomson unsigned int freq_out)
111648e27874SAdam Thomson {
1117192ce2fbSKuninori Morimoto struct da732x_priv *da732x = snd_soc_component_get_drvdata(component);
111848e27874SAdam Thomson int fref, indiv;
111948e27874SAdam Thomson u8 div_lo, div_mid, div_hi;
112048e27874SAdam Thomson u64 frac_div;
112148e27874SAdam Thomson
112248e27874SAdam Thomson /* Disable PLL */
112348e27874SAdam Thomson if (freq_out == 0) {
1124192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_PLL_CTRL,
112548e27874SAdam Thomson DA732X_PLL_EN, 0);
112648e27874SAdam Thomson da732x->pll_en = false;
112748e27874SAdam Thomson return 0;
112848e27874SAdam Thomson }
112948e27874SAdam Thomson
113048e27874SAdam Thomson if (da732x->pll_en)
113148e27874SAdam Thomson return -EBUSY;
113248e27874SAdam Thomson
113348e27874SAdam Thomson if (source == DA732X_SRCCLK_MCLK) {
113448e27874SAdam Thomson /* Validate Sysclk rate */
113548e27874SAdam Thomson switch (da732x->sysclk) {
113648e27874SAdam Thomson case 11290000:
113748e27874SAdam Thomson case 12288000:
113848e27874SAdam Thomson case 22580000:
113948e27874SAdam Thomson case 24576000:
114048e27874SAdam Thomson case 45160000:
114148e27874SAdam Thomson case 49152000:
1142192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_PLL_CTRL,
114348e27874SAdam Thomson DA732X_PLL_BYPASS);
114448e27874SAdam Thomson return 0;
114548e27874SAdam Thomson default:
1146192ce2fbSKuninori Morimoto dev_err(component->dev,
114748e27874SAdam Thomson "Cannot use PLL Bypass, invalid SYSCLK rate\n");
114848e27874SAdam Thomson return -EINVAL;
114948e27874SAdam Thomson }
115048e27874SAdam Thomson }
115148e27874SAdam Thomson
1152192ce2fbSKuninori Morimoto indiv = da732x_get_input_div(component, da732x->sysclk);
115348e27874SAdam Thomson if (indiv < 0)
115448e27874SAdam Thomson return indiv;
115548e27874SAdam Thomson
1156945b0b58SPierre-Louis Bossart fref = da732x->sysclk / BIT(indiv);
115748e27874SAdam Thomson div_hi = freq_out / fref;
115848e27874SAdam Thomson frac_div = (u64)(freq_out % fref) * 8192ULL;
115948e27874SAdam Thomson do_div(frac_div, fref);
116048e27874SAdam Thomson div_mid = (frac_div >> DA732X_1BYTE_SHIFT) & DA732X_U8_MASK;
116148e27874SAdam Thomson div_lo = (frac_div) & DA732X_U8_MASK;
116248e27874SAdam Thomson
1163192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_PLL_DIV_LO, div_lo);
1164192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_PLL_DIV_MID, div_mid);
1165192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_PLL_DIV_HI, div_hi);
116648e27874SAdam Thomson
1167192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_PLL_CTRL, DA732X_PLL_EN,
116848e27874SAdam Thomson DA732X_PLL_EN);
116948e27874SAdam Thomson
117048e27874SAdam Thomson da732x->pll_en = true;
117148e27874SAdam Thomson
117248e27874SAdam Thomson return 0;
117348e27874SAdam Thomson }
117448e27874SAdam Thomson
da732x_set_dai_sysclk(struct snd_soc_dai * dai,int clk_id,unsigned int freq,int dir)117548e27874SAdam Thomson static int da732x_set_dai_sysclk(struct snd_soc_dai *dai, int clk_id,
117648e27874SAdam Thomson unsigned int freq, int dir)
117748e27874SAdam Thomson {
1178192ce2fbSKuninori Morimoto struct snd_soc_component *component = dai->component;
1179192ce2fbSKuninori Morimoto struct da732x_priv *da732x = snd_soc_component_get_drvdata(component);
118048e27874SAdam Thomson
118148e27874SAdam Thomson da732x->sysclk = freq;
118248e27874SAdam Thomson
118348e27874SAdam Thomson return 0;
118448e27874SAdam Thomson }
118548e27874SAdam Thomson
118648e27874SAdam Thomson #define DA732X_RATES SNDRV_PCM_RATE_8000_96000
118748e27874SAdam Thomson
118848e27874SAdam Thomson #define DA732X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
118948e27874SAdam Thomson SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
119048e27874SAdam Thomson
1191a01da00cSAxel Lin static const struct snd_soc_dai_ops da732x_dai_ops = {
119248e27874SAdam Thomson .hw_params = da732x_hw_params,
119348e27874SAdam Thomson .set_fmt = da732x_set_dai_fmt,
119448e27874SAdam Thomson .set_sysclk = da732x_set_dai_sysclk,
119548e27874SAdam Thomson };
119648e27874SAdam Thomson
119748e27874SAdam Thomson static struct snd_soc_dai_driver da732x_dai[] = {
119848e27874SAdam Thomson {
119948e27874SAdam Thomson .name = "DA732X_AIFA",
120048e27874SAdam Thomson .id = DA732X_DAI_ID1,
120148e27874SAdam Thomson .base = DA732X_REG_AIFA1,
120248e27874SAdam Thomson .playback = {
120348e27874SAdam Thomson .stream_name = "AIFA Playback",
120448e27874SAdam Thomson .channels_min = 1,
120548e27874SAdam Thomson .channels_max = 2,
120648e27874SAdam Thomson .rates = DA732X_RATES,
120748e27874SAdam Thomson .formats = DA732X_FORMATS,
120848e27874SAdam Thomson },
120948e27874SAdam Thomson .capture = {
121048e27874SAdam Thomson .stream_name = "AIFA Capture",
121148e27874SAdam Thomson .channels_min = 1,
121248e27874SAdam Thomson .channels_max = 2,
121348e27874SAdam Thomson .rates = DA732X_RATES,
121448e27874SAdam Thomson .formats = DA732X_FORMATS,
121548e27874SAdam Thomson },
1216a01da00cSAxel Lin .ops = &da732x_dai_ops,
121748e27874SAdam Thomson },
121848e27874SAdam Thomson {
121948e27874SAdam Thomson .name = "DA732X_AIFB",
122048e27874SAdam Thomson .id = DA732X_DAI_ID2,
122148e27874SAdam Thomson .base = DA732X_REG_AIFB1,
122248e27874SAdam Thomson .playback = {
122348e27874SAdam Thomson .stream_name = "AIFB Playback",
122448e27874SAdam Thomson .channels_min = 1,
122548e27874SAdam Thomson .channels_max = 2,
122648e27874SAdam Thomson .rates = DA732X_RATES,
122748e27874SAdam Thomson .formats = DA732X_FORMATS,
122848e27874SAdam Thomson },
122948e27874SAdam Thomson .capture = {
123048e27874SAdam Thomson .stream_name = "AIFB Capture",
123148e27874SAdam Thomson .channels_min = 1,
123248e27874SAdam Thomson .channels_max = 2,
123348e27874SAdam Thomson .rates = DA732X_RATES,
123448e27874SAdam Thomson .formats = DA732X_FORMATS,
123548e27874SAdam Thomson },
1236a01da00cSAxel Lin .ops = &da732x_dai_ops,
123748e27874SAdam Thomson },
123848e27874SAdam Thomson };
123948e27874SAdam Thomson
da732x_volatile(struct device * dev,unsigned int reg)124075306820SMark Brown static bool da732x_volatile(struct device *dev, unsigned int reg)
124175306820SMark Brown {
124275306820SMark Brown switch (reg) {
124375306820SMark Brown case DA732X_REG_HPL_DAC_OFF_CNTL:
124475306820SMark Brown case DA732X_REG_HPR_DAC_OFF_CNTL:
124575306820SMark Brown return true;
124675306820SMark Brown default:
124775306820SMark Brown return false;
124875306820SMark Brown }
124975306820SMark Brown }
125075306820SMark Brown
125148e27874SAdam Thomson static const struct regmap_config da732x_regmap = {
125248e27874SAdam Thomson .reg_bits = 8,
125348e27874SAdam Thomson .val_bits = 8,
125448e27874SAdam Thomson
125548e27874SAdam Thomson .max_register = DA732X_MAX_REG,
125675306820SMark Brown .volatile_reg = da732x_volatile,
125748e27874SAdam Thomson .reg_defaults = da732x_reg_cache,
125848e27874SAdam Thomson .num_reg_defaults = ARRAY_SIZE(da732x_reg_cache),
125948e27874SAdam Thomson .cache_type = REGCACHE_RBTREE,
126048e27874SAdam Thomson };
126148e27874SAdam Thomson
126248e27874SAdam Thomson
da732x_dac_offset_adjust(struct snd_soc_component * component)1263192ce2fbSKuninori Morimoto static void da732x_dac_offset_adjust(struct snd_soc_component *component)
126448e27874SAdam Thomson {
126548e27874SAdam Thomson u8 offset[DA732X_HP_DACS];
126648e27874SAdam Thomson u8 sign[DA732X_HP_DACS];
126748e27874SAdam Thomson u8 step = DA732X_DAC_OFFSET_STEP;
126848e27874SAdam Thomson
126948e27874SAdam Thomson /* Initialize DAC offset calibration circuits and registers */
1270192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL_DAC_OFFSET,
127148e27874SAdam Thomson DA732X_HP_DAC_OFFSET_TRIM_VAL);
1272192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR_DAC_OFFSET,
127348e27874SAdam Thomson DA732X_HP_DAC_OFFSET_TRIM_VAL);
1274192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL_DAC_OFF_CNTL,
127548e27874SAdam Thomson DA732X_HP_DAC_OFF_CALIBRATION |
127648e27874SAdam Thomson DA732X_HP_DAC_OFF_SCALE_STEPS);
1277192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR_DAC_OFF_CNTL,
127848e27874SAdam Thomson DA732X_HP_DAC_OFF_CALIBRATION |
127948e27874SAdam Thomson DA732X_HP_DAC_OFF_SCALE_STEPS);
128048e27874SAdam Thomson
128148e27874SAdam Thomson /* Wait for voltage stabilization */
128248e27874SAdam Thomson msleep(DA732X_WAIT_FOR_STABILIZATION);
128348e27874SAdam Thomson
128448e27874SAdam Thomson /* Check DAC offset sign */
12852925b582SKuninori Morimoto sign[DA732X_HPL_DAC] = (snd_soc_component_read(component, DA732X_REG_HPL_DAC_OFF_CNTL) &
128648e27874SAdam Thomson DA732X_HP_DAC_OFF_CNTL_COMPO);
12872925b582SKuninori Morimoto sign[DA732X_HPR_DAC] = (snd_soc_component_read(component, DA732X_REG_HPR_DAC_OFF_CNTL) &
128848e27874SAdam Thomson DA732X_HP_DAC_OFF_CNTL_COMPO);
128948e27874SAdam Thomson
129048e27874SAdam Thomson /* Binary search DAC offset values (both channels at once) */
129148e27874SAdam Thomson offset[DA732X_HPL_DAC] = sign[DA732X_HPL_DAC] << DA732X_HP_DAC_COMPO_SHIFT;
129248e27874SAdam Thomson offset[DA732X_HPR_DAC] = sign[DA732X_HPR_DAC] << DA732X_HP_DAC_COMPO_SHIFT;
129348e27874SAdam Thomson
129448e27874SAdam Thomson do {
129548e27874SAdam Thomson offset[DA732X_HPL_DAC] |= step;
129648e27874SAdam Thomson offset[DA732X_HPR_DAC] |= step;
1297192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL_DAC_OFFSET,
129848e27874SAdam Thomson ~offset[DA732X_HPL_DAC] & DA732X_HP_DAC_OFF_MASK);
1299192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR_DAC_OFFSET,
130048e27874SAdam Thomson ~offset[DA732X_HPR_DAC] & DA732X_HP_DAC_OFF_MASK);
130148e27874SAdam Thomson
130248e27874SAdam Thomson msleep(DA732X_WAIT_FOR_STABILIZATION);
130348e27874SAdam Thomson
13042925b582SKuninori Morimoto if ((snd_soc_component_read(component, DA732X_REG_HPL_DAC_OFF_CNTL) &
130548e27874SAdam Thomson DA732X_HP_DAC_OFF_CNTL_COMPO) ^ sign[DA732X_HPL_DAC])
130648e27874SAdam Thomson offset[DA732X_HPL_DAC] &= ~step;
13072925b582SKuninori Morimoto if ((snd_soc_component_read(component, DA732X_REG_HPR_DAC_OFF_CNTL) &
130848e27874SAdam Thomson DA732X_HP_DAC_OFF_CNTL_COMPO) ^ sign[DA732X_HPR_DAC])
130948e27874SAdam Thomson offset[DA732X_HPR_DAC] &= ~step;
131048e27874SAdam Thomson
131148e27874SAdam Thomson step >>= 1;
131248e27874SAdam Thomson } while (step);
131348e27874SAdam Thomson
131448e27874SAdam Thomson /* Write final DAC offsets to registers */
1315192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL_DAC_OFFSET,
131648e27874SAdam Thomson ~offset[DA732X_HPL_DAC] & DA732X_HP_DAC_OFF_MASK);
1317192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR_DAC_OFFSET,
131848e27874SAdam Thomson ~offset[DA732X_HPR_DAC] & DA732X_HP_DAC_OFF_MASK);
131948e27874SAdam Thomson
132048e27874SAdam Thomson /* End DAC calibration mode */
1321192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL_DAC_OFF_CNTL,
132248e27874SAdam Thomson DA732X_HP_DAC_OFF_SCALE_STEPS);
1323192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR_DAC_OFF_CNTL,
132448e27874SAdam Thomson DA732X_HP_DAC_OFF_SCALE_STEPS);
132548e27874SAdam Thomson }
132648e27874SAdam Thomson
da732x_output_offset_adjust(struct snd_soc_component * component)1327192ce2fbSKuninori Morimoto static void da732x_output_offset_adjust(struct snd_soc_component *component)
132848e27874SAdam Thomson {
132948e27874SAdam Thomson u8 offset[DA732X_HP_AMPS];
133048e27874SAdam Thomson u8 sign[DA732X_HP_AMPS];
133148e27874SAdam Thomson u8 step = DA732X_OUTPUT_OFFSET_STEP;
133248e27874SAdam Thomson
133348e27874SAdam Thomson offset[DA732X_HPL_AMP] = DA732X_HP_OUT_TRIM_VAL;
133448e27874SAdam Thomson offset[DA732X_HPR_AMP] = DA732X_HP_OUT_TRIM_VAL;
133548e27874SAdam Thomson
133648e27874SAdam Thomson /* Initialize output offset calibration circuits and registers */
1337192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL_OUT_OFFSET, DA732X_HP_OUT_TRIM_VAL);
1338192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR_OUT_OFFSET, DA732X_HP_OUT_TRIM_VAL);
1339192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL,
134048e27874SAdam Thomson DA732X_HP_OUT_COMP | DA732X_HP_OUT_EN);
1341192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR,
134248e27874SAdam Thomson DA732X_HP_OUT_COMP | DA732X_HP_OUT_EN);
134348e27874SAdam Thomson
134448e27874SAdam Thomson /* Wait for voltage stabilization */
134548e27874SAdam Thomson msleep(DA732X_WAIT_FOR_STABILIZATION);
134648e27874SAdam Thomson
134748e27874SAdam Thomson /* Check output offset sign */
13482925b582SKuninori Morimoto sign[DA732X_HPL_AMP] = snd_soc_component_read(component, DA732X_REG_HPL) &
134948e27874SAdam Thomson DA732X_HP_OUT_COMPO;
13502925b582SKuninori Morimoto sign[DA732X_HPR_AMP] = snd_soc_component_read(component, DA732X_REG_HPR) &
135148e27874SAdam Thomson DA732X_HP_OUT_COMPO;
135248e27874SAdam Thomson
1353192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL, DA732X_HP_OUT_COMP |
135448e27874SAdam Thomson (sign[DA732X_HPL_AMP] >> DA732X_HP_OUT_COMPO_SHIFT) |
135548e27874SAdam Thomson DA732X_HP_OUT_EN);
1356192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR, DA732X_HP_OUT_COMP |
135748e27874SAdam Thomson (sign[DA732X_HPR_AMP] >> DA732X_HP_OUT_COMPO_SHIFT) |
135848e27874SAdam Thomson DA732X_HP_OUT_EN);
135948e27874SAdam Thomson
136048e27874SAdam Thomson /* Binary search output offset values (both channels at once) */
136148e27874SAdam Thomson do {
136248e27874SAdam Thomson offset[DA732X_HPL_AMP] |= step;
136348e27874SAdam Thomson offset[DA732X_HPR_AMP] |= step;
1364192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL_OUT_OFFSET,
136548e27874SAdam Thomson offset[DA732X_HPL_AMP]);
1366192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR_OUT_OFFSET,
136748e27874SAdam Thomson offset[DA732X_HPR_AMP]);
136848e27874SAdam Thomson
136948e27874SAdam Thomson msleep(DA732X_WAIT_FOR_STABILIZATION);
137048e27874SAdam Thomson
13712925b582SKuninori Morimoto if ((snd_soc_component_read(component, DA732X_REG_HPL) &
137248e27874SAdam Thomson DA732X_HP_OUT_COMPO) ^ sign[DA732X_HPL_AMP])
137348e27874SAdam Thomson offset[DA732X_HPL_AMP] &= ~step;
13742925b582SKuninori Morimoto if ((snd_soc_component_read(component, DA732X_REG_HPR) &
137548e27874SAdam Thomson DA732X_HP_OUT_COMPO) ^ sign[DA732X_HPR_AMP])
137648e27874SAdam Thomson offset[DA732X_HPR_AMP] &= ~step;
137748e27874SAdam Thomson
137848e27874SAdam Thomson step >>= 1;
137948e27874SAdam Thomson } while (step);
138048e27874SAdam Thomson
138148e27874SAdam Thomson /* Write final DAC offsets to registers */
1382192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL_OUT_OFFSET, offset[DA732X_HPL_AMP]);
1383192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR_OUT_OFFSET, offset[DA732X_HPR_AMP]);
138448e27874SAdam Thomson }
138548e27874SAdam Thomson
da732x_hp_dc_offset_cancellation(struct snd_soc_component * component)1386192ce2fbSKuninori Morimoto static void da732x_hp_dc_offset_cancellation(struct snd_soc_component *component)
138748e27874SAdam Thomson {
138848e27874SAdam Thomson /* Make sure that we have Soft Mute enabled */
1389192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_DAC1_SOFTMUTE, DA732X_SOFTMUTE_EN |
139048e27874SAdam Thomson DA732X_GAIN_RAMPED | DA732X_16_SAMPLES);
1391192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_DAC1_SEL, DA732X_DACL_EN |
139248e27874SAdam Thomson DA732X_DACR_EN | DA732X_DACL_SDM | DA732X_DACR_SDM |
139348e27874SAdam Thomson DA732X_DACL_MUTE | DA732X_DACR_MUTE);
1394192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL, DA732X_HP_OUT_DAC_EN |
139548e27874SAdam Thomson DA732X_HP_OUT_MUTE | DA732X_HP_OUT_EN);
1396192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR, DA732X_HP_OUT_EN |
139748e27874SAdam Thomson DA732X_HP_OUT_MUTE | DA732X_HP_OUT_DAC_EN);
139848e27874SAdam Thomson
1399192ce2fbSKuninori Morimoto da732x_dac_offset_adjust(component);
1400192ce2fbSKuninori Morimoto da732x_output_offset_adjust(component);
140148e27874SAdam Thomson
1402192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_DAC1_SEL, DA732X_DACS_DIS);
1403192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPL, DA732X_HP_DIS);
1404192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HPR, DA732X_HP_DIS);
140548e27874SAdam Thomson }
140648e27874SAdam Thomson
da732x_set_bias_level(struct snd_soc_component * component,enum snd_soc_bias_level level)1407192ce2fbSKuninori Morimoto static int da732x_set_bias_level(struct snd_soc_component *component,
140848e27874SAdam Thomson enum snd_soc_bias_level level)
140948e27874SAdam Thomson {
1410192ce2fbSKuninori Morimoto struct da732x_priv *da732x = snd_soc_component_get_drvdata(component);
141148e27874SAdam Thomson
141248e27874SAdam Thomson switch (level) {
141348e27874SAdam Thomson case SND_SOC_BIAS_ON:
1414192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_BIAS_EN,
141548e27874SAdam Thomson DA732X_BIAS_BOOST_MASK,
141648e27874SAdam Thomson DA732X_BIAS_BOOST_100PC);
141748e27874SAdam Thomson break;
141848e27874SAdam Thomson case SND_SOC_BIAS_PREPARE:
141948e27874SAdam Thomson break;
142048e27874SAdam Thomson case SND_SOC_BIAS_STANDBY:
1421192ce2fbSKuninori Morimoto if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
142248e27874SAdam Thomson /* Init Codec */
1423192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_REF1,
142448e27874SAdam Thomson DA732X_VMID_FASTCHG);
1425192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_BIAS_EN,
142648e27874SAdam Thomson DA732X_BIAS_EN);
142748e27874SAdam Thomson
142848e27874SAdam Thomson mdelay(DA732X_STARTUP_DELAY);
142948e27874SAdam Thomson
143048e27874SAdam Thomson /* Disable Fast Charge and enable DAC ref voltage */
1431192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_REF1,
143248e27874SAdam Thomson DA732X_REFBUFX2_EN);
143348e27874SAdam Thomson
143448e27874SAdam Thomson /* Enable bypass DSP routing */
1435192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_DATA_ROUTE,
143648e27874SAdam Thomson DA732X_BYPASS_DSP);
143748e27874SAdam Thomson
143848e27874SAdam Thomson /* Enable Digital subsystem */
1439192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_DSP_CTRL,
144048e27874SAdam Thomson DA732X_DIGITAL_EN);
144148e27874SAdam Thomson
1442192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_SPARE1_OUT,
144348e27874SAdam Thomson DA732X_HP_DRIVER_EN |
144448e27874SAdam Thomson DA732X_HP_GATE_LOW |
144548e27874SAdam Thomson DA732X_HP_LOOP_GAIN_CTRL);
1446192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_HP_LIN1_GNDSEL,
144748e27874SAdam Thomson DA732X_HP_OUT_GNDSEL);
144848e27874SAdam Thomson
1449192ce2fbSKuninori Morimoto da732x_set_charge_pump(component, DA732X_ENABLE_CP);
145048e27874SAdam Thomson
1451192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_CLK_EN1,
145248e27874SAdam Thomson DA732X_SYS3_CLK_EN | DA732X_PC_CLK_EN);
145348e27874SAdam Thomson
145448e27874SAdam Thomson /* Enable Zero Crossing */
1455192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_INP_ZC_EN,
145648e27874SAdam Thomson DA732X_MIC1_PRE_ZC_EN |
145748e27874SAdam Thomson DA732X_MIC1_ZC_EN |
145848e27874SAdam Thomson DA732X_MIC2_PRE_ZC_EN |
145948e27874SAdam Thomson DA732X_MIC2_ZC_EN |
146048e27874SAdam Thomson DA732X_AUXL_ZC_EN |
146148e27874SAdam Thomson DA732X_AUXR_ZC_EN |
146248e27874SAdam Thomson DA732X_MIC3_PRE_ZC_EN |
146348e27874SAdam Thomson DA732X_MIC3_ZC_EN);
1464192ce2fbSKuninori Morimoto snd_soc_component_write(component, DA732X_REG_OUT_ZC_EN,
146548e27874SAdam Thomson DA732X_HPL_ZC_EN | DA732X_HPR_ZC_EN |
146648e27874SAdam Thomson DA732X_LIN2_ZC_EN | DA732X_LIN3_ZC_EN |
146748e27874SAdam Thomson DA732X_LIN4_ZC_EN);
146848e27874SAdam Thomson
1469192ce2fbSKuninori Morimoto da732x_hp_dc_offset_cancellation(component);
147048e27874SAdam Thomson
147130812ccaSLars-Peter Clausen regcache_cache_only(da732x->regmap, false);
147230812ccaSLars-Peter Clausen regcache_sync(da732x->regmap);
147348e27874SAdam Thomson } else {
1474192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_BIAS_EN,
147548e27874SAdam Thomson DA732X_BIAS_BOOST_MASK,
147648e27874SAdam Thomson DA732X_BIAS_BOOST_50PC);
1477192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_PLL_CTRL,
147848e27874SAdam Thomson DA732X_PLL_EN, 0);
147948e27874SAdam Thomson da732x->pll_en = false;
148048e27874SAdam Thomson }
148148e27874SAdam Thomson break;
148248e27874SAdam Thomson case SND_SOC_BIAS_OFF:
148330812ccaSLars-Peter Clausen regcache_cache_only(da732x->regmap, true);
1484192ce2fbSKuninori Morimoto da732x_set_charge_pump(component, DA732X_DISABLE_CP);
1485192ce2fbSKuninori Morimoto snd_soc_component_update_bits(component, DA732X_REG_BIAS_EN, DA732X_BIAS_EN,
148648e27874SAdam Thomson DA732X_BIAS_DIS);
148748e27874SAdam Thomson da732x->pll_en = false;
148848e27874SAdam Thomson break;
148948e27874SAdam Thomson }
149048e27874SAdam Thomson
149148e27874SAdam Thomson return 0;
149248e27874SAdam Thomson }
149348e27874SAdam Thomson
1494192ce2fbSKuninori Morimoto static const struct snd_soc_component_driver soc_component_dev_da732x = {
149548e27874SAdam Thomson .set_bias_level = da732x_set_bias_level,
149648e27874SAdam Thomson .controls = da732x_snd_controls,
149748e27874SAdam Thomson .num_controls = ARRAY_SIZE(da732x_snd_controls),
149848e27874SAdam Thomson .dapm_widgets = da732x_dapm_widgets,
149948e27874SAdam Thomson .num_dapm_widgets = ARRAY_SIZE(da732x_dapm_widgets),
150048e27874SAdam Thomson .dapm_routes = da732x_dapm_routes,
150148e27874SAdam Thomson .num_dapm_routes = ARRAY_SIZE(da732x_dapm_routes),
150248e27874SAdam Thomson .set_pll = da732x_set_dai_pll,
1503192ce2fbSKuninori Morimoto .idle_bias_on = 1,
1504192ce2fbSKuninori Morimoto .use_pmdown_time = 1,
1505192ce2fbSKuninori Morimoto .endianness = 1,
150648e27874SAdam Thomson };
150748e27874SAdam Thomson
da732x_i2c_probe(struct i2c_client * i2c)150889be5dc6SStephen Kitt static int da732x_i2c_probe(struct i2c_client *i2c)
150948e27874SAdam Thomson {
151048e27874SAdam Thomson struct da732x_priv *da732x;
151148e27874SAdam Thomson unsigned int reg;
151248e27874SAdam Thomson int ret;
151348e27874SAdam Thomson
151448e27874SAdam Thomson da732x = devm_kzalloc(&i2c->dev, sizeof(struct da732x_priv),
151548e27874SAdam Thomson GFP_KERNEL);
151648e27874SAdam Thomson if (!da732x)
151748e27874SAdam Thomson return -ENOMEM;
151848e27874SAdam Thomson
151948e27874SAdam Thomson i2c_set_clientdata(i2c, da732x);
152048e27874SAdam Thomson
152148e27874SAdam Thomson da732x->regmap = devm_regmap_init_i2c(i2c, &da732x_regmap);
152248e27874SAdam Thomson if (IS_ERR(da732x->regmap)) {
152348e27874SAdam Thomson ret = PTR_ERR(da732x->regmap);
152448e27874SAdam Thomson dev_err(&i2c->dev, "Failed to initialize regmap\n");
152548e27874SAdam Thomson goto err;
152648e27874SAdam Thomson }
152748e27874SAdam Thomson
152848e27874SAdam Thomson ret = regmap_read(da732x->regmap, DA732X_REG_ID, ®);
152948e27874SAdam Thomson if (ret < 0) {
153048e27874SAdam Thomson dev_err(&i2c->dev, "Failed to read ID register: %d\n", ret);
153148e27874SAdam Thomson goto err;
153248e27874SAdam Thomson }
153348e27874SAdam Thomson
153448e27874SAdam Thomson dev_info(&i2c->dev, "Revision: %d.%d\n",
153505b00067SAxel Lin (reg & DA732X_ID_MAJOR_MASK) >> 4,
153605b00067SAxel Lin (reg & DA732X_ID_MINOR_MASK));
153748e27874SAdam Thomson
1538192ce2fbSKuninori Morimoto ret = devm_snd_soc_register_component(&i2c->dev,
1539192ce2fbSKuninori Morimoto &soc_component_dev_da732x,
154048e27874SAdam Thomson da732x_dai, ARRAY_SIZE(da732x_dai));
154148e27874SAdam Thomson if (ret != 0)
1542192ce2fbSKuninori Morimoto dev_err(&i2c->dev, "Failed to register component.\n");
154348e27874SAdam Thomson
154448e27874SAdam Thomson err:
154548e27874SAdam Thomson return ret;
154648e27874SAdam Thomson }
154748e27874SAdam Thomson
154848e27874SAdam Thomson static const struct i2c_device_id da732x_i2c_id[] = {
1549*ba2a2c37SUwe Kleine-König { "da7320"},
155048e27874SAdam Thomson { }
155148e27874SAdam Thomson };
155248e27874SAdam Thomson MODULE_DEVICE_TABLE(i2c, da732x_i2c_id);
155348e27874SAdam Thomson
155448e27874SAdam Thomson static struct i2c_driver da732x_i2c_driver = {
155548e27874SAdam Thomson .driver = {
155648e27874SAdam Thomson .name = "da7320",
155748e27874SAdam Thomson },
15589abcd240SUwe Kleine-König .probe = da732x_i2c_probe,
155948e27874SAdam Thomson .id_table = da732x_i2c_id,
156048e27874SAdam Thomson };
156148e27874SAdam Thomson
156248e27874SAdam Thomson module_i2c_driver(da732x_i2c_driver);
156348e27874SAdam Thomson
156448e27874SAdam Thomson
156548e27874SAdam Thomson MODULE_DESCRIPTION("ASoC DA732X driver");
156648e27874SAdam Thomson MODULE_AUTHOR("Michal Hajduk <michal.hajduk@diasemi.com>");
156748e27874SAdam Thomson MODULE_LICENSE("GPL");
1568