18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci// Copyright (c) 2016, The Linux Foundation. All rights reserved.
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci#include <linux/module.h>
58c2ecf20Sopenharmony_ci#include <linux/err.h>
68c2ecf20Sopenharmony_ci#include <linux/kernel.h>
78c2ecf20Sopenharmony_ci#include <linux/delay.h>
88c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h>
98c2ecf20Sopenharmony_ci#include <linux/types.h>
108c2ecf20Sopenharmony_ci#include <linux/clk.h>
118c2ecf20Sopenharmony_ci#include <linux/of.h>
128c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
138c2ecf20Sopenharmony_ci#include <linux/regmap.h>
148c2ecf20Sopenharmony_ci#include <sound/soc.h>
158c2ecf20Sopenharmony_ci#include <sound/pcm.h>
168c2ecf20Sopenharmony_ci#include <sound/pcm_params.h>
178c2ecf20Sopenharmony_ci#include <sound/tlv.h>
188c2ecf20Sopenharmony_ci#include <sound/jack.h>
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define CDC_D_REVISION1			(0xf000)
218c2ecf20Sopenharmony_ci#define CDC_D_PERPH_SUBTYPE		(0xf005)
228c2ecf20Sopenharmony_ci#define CDC_D_INT_EN_SET		(0xf015)
238c2ecf20Sopenharmony_ci#define CDC_D_INT_EN_CLR		(0xf016)
248c2ecf20Sopenharmony_ci#define MBHC_SWITCH_INT			BIT(7)
258c2ecf20Sopenharmony_ci#define MBHC_MIC_ELECTRICAL_INS_REM_DET	BIT(6)
268c2ecf20Sopenharmony_ci#define MBHC_BUTTON_PRESS_DET		BIT(5)
278c2ecf20Sopenharmony_ci#define MBHC_BUTTON_RELEASE_DET		BIT(4)
288c2ecf20Sopenharmony_ci#define CDC_D_CDC_RST_CTL		(0xf046)
298c2ecf20Sopenharmony_ci#define RST_CTL_DIG_SW_RST_N_MASK	BIT(7)
308c2ecf20Sopenharmony_ci#define RST_CTL_DIG_SW_RST_N_RESET	0
318c2ecf20Sopenharmony_ci#define RST_CTL_DIG_SW_RST_N_REMOVE_RESET BIT(7)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define CDC_D_CDC_TOP_CLK_CTL		(0xf048)
348c2ecf20Sopenharmony_ci#define TOP_CLK_CTL_A_MCLK_MCLK2_EN_MASK (BIT(2) | BIT(3))
358c2ecf20Sopenharmony_ci#define TOP_CLK_CTL_A_MCLK_EN_ENABLE	 BIT(2)
368c2ecf20Sopenharmony_ci#define TOP_CLK_CTL_A_MCLK2_EN_ENABLE	BIT(3)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define CDC_D_CDC_ANA_CLK_CTL		(0xf049)
398c2ecf20Sopenharmony_ci#define ANA_CLK_CTL_EAR_HPHR_CLK_EN_MASK BIT(0)
408c2ecf20Sopenharmony_ci#define ANA_CLK_CTL_EAR_HPHR_CLK_EN	BIT(0)
418c2ecf20Sopenharmony_ci#define ANA_CLK_CTL_EAR_HPHL_CLK_EN	BIT(1)
428c2ecf20Sopenharmony_ci#define ANA_CLK_CTL_SPKR_CLK_EN_MASK	BIT(4)
438c2ecf20Sopenharmony_ci#define ANA_CLK_CTL_SPKR_CLK_EN	BIT(4)
448c2ecf20Sopenharmony_ci#define ANA_CLK_CTL_TXA_CLK25_EN	BIT(5)
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci#define CDC_D_CDC_DIG_CLK_CTL		(0xf04A)
478c2ecf20Sopenharmony_ci#define DIG_CLK_CTL_RXD1_CLK_EN		BIT(0)
488c2ecf20Sopenharmony_ci#define DIG_CLK_CTL_RXD2_CLK_EN		BIT(1)
498c2ecf20Sopenharmony_ci#define DIG_CLK_CTL_RXD3_CLK_EN		BIT(2)
508c2ecf20Sopenharmony_ci#define DIG_CLK_CTL_D_MBHC_CLK_EN_MASK	BIT(3)
518c2ecf20Sopenharmony_ci#define DIG_CLK_CTL_D_MBHC_CLK_EN	BIT(3)
528c2ecf20Sopenharmony_ci#define DIG_CLK_CTL_TXD_CLK_EN		BIT(4)
538c2ecf20Sopenharmony_ci#define DIG_CLK_CTL_NCP_CLK_EN_MASK	BIT(6)
548c2ecf20Sopenharmony_ci#define DIG_CLK_CTL_NCP_CLK_EN		BIT(6)
558c2ecf20Sopenharmony_ci#define DIG_CLK_CTL_RXD_PDM_CLK_EN_MASK	BIT(7)
568c2ecf20Sopenharmony_ci#define DIG_CLK_CTL_RXD_PDM_CLK_EN	BIT(7)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define CDC_D_CDC_CONN_TX1_CTL		(0xf050)
598c2ecf20Sopenharmony_ci#define CONN_TX1_SERIAL_TX1_MUX		GENMASK(1, 0)
608c2ecf20Sopenharmony_ci#define CONN_TX1_SERIAL_TX1_ADC_1	0x0
618c2ecf20Sopenharmony_ci#define CONN_TX1_SERIAL_TX1_RX_PDM_LB	0x1
628c2ecf20Sopenharmony_ci#define CONN_TX1_SERIAL_TX1_ZERO	0x2
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci#define CDC_D_CDC_CONN_TX2_CTL		(0xf051)
658c2ecf20Sopenharmony_ci#define CONN_TX2_SERIAL_TX2_MUX		GENMASK(1, 0)
668c2ecf20Sopenharmony_ci#define CONN_TX2_SERIAL_TX2_ADC_2	0x0
678c2ecf20Sopenharmony_ci#define CONN_TX2_SERIAL_TX2_RX_PDM_LB	0x1
688c2ecf20Sopenharmony_ci#define CONN_TX2_SERIAL_TX2_ZERO	0x2
698c2ecf20Sopenharmony_ci#define CDC_D_CDC_CONN_HPHR_DAC_CTL	(0xf052)
708c2ecf20Sopenharmony_ci#define CDC_D_CDC_CONN_RX1_CTL		(0xf053)
718c2ecf20Sopenharmony_ci#define CDC_D_CDC_CONN_RX2_CTL		(0xf054)
728c2ecf20Sopenharmony_ci#define CDC_D_CDC_CONN_RX3_CTL		(0xf055)
738c2ecf20Sopenharmony_ci#define CDC_D_CDC_CONN_RX_LB_CTL	(0xf056)
748c2ecf20Sopenharmony_ci#define CDC_D_SEC_ACCESS		(0xf0D0)
758c2ecf20Sopenharmony_ci#define CDC_D_PERPH_RESET_CTL3		(0xf0DA)
768c2ecf20Sopenharmony_ci#define CDC_D_PERPH_RESET_CTL4		(0xf0DB)
778c2ecf20Sopenharmony_ci#define CDC_A_REVISION1			(0xf100)
788c2ecf20Sopenharmony_ci#define CDC_A_REVISION2			(0xf101)
798c2ecf20Sopenharmony_ci#define CDC_A_REVISION3			(0xf102)
808c2ecf20Sopenharmony_ci#define CDC_A_REVISION4			(0xf103)
818c2ecf20Sopenharmony_ci#define CDC_A_PERPH_TYPE		(0xf104)
828c2ecf20Sopenharmony_ci#define CDC_A_PERPH_SUBTYPE		(0xf105)
838c2ecf20Sopenharmony_ci#define CDC_A_INT_RT_STS		(0xf110)
848c2ecf20Sopenharmony_ci#define CDC_A_INT_SET_TYPE		(0xf111)
858c2ecf20Sopenharmony_ci#define CDC_A_INT_POLARITY_HIGH		(0xf112)
868c2ecf20Sopenharmony_ci#define CDC_A_INT_POLARITY_LOW		(0xf113)
878c2ecf20Sopenharmony_ci#define CDC_A_INT_LATCHED_CLR		(0xf114)
888c2ecf20Sopenharmony_ci#define CDC_A_INT_EN_SET		(0xf115)
898c2ecf20Sopenharmony_ci#define CDC_A_INT_EN_CLR		(0xf116)
908c2ecf20Sopenharmony_ci#define CDC_A_INT_LATCHED_STS		(0xf118)
918c2ecf20Sopenharmony_ci#define CDC_A_INT_PENDING_STS		(0xf119)
928c2ecf20Sopenharmony_ci#define CDC_A_INT_MID_SEL		(0xf11A)
938c2ecf20Sopenharmony_ci#define CDC_A_INT_PRIORITY		(0xf11B)
948c2ecf20Sopenharmony_ci#define CDC_A_MICB_1_EN			(0xf140)
958c2ecf20Sopenharmony_ci#define MICB_1_EN_MICB_ENABLE		BIT(7)
968c2ecf20Sopenharmony_ci#define MICB_1_EN_BYP_CAP_MASK		BIT(6)
978c2ecf20Sopenharmony_ci#define MICB_1_EN_NO_EXT_BYP_CAP	BIT(6)
988c2ecf20Sopenharmony_ci#define MICB_1_EN_EXT_BYP_CAP		0
998c2ecf20Sopenharmony_ci#define MICB_1_EN_PULL_DOWN_EN_MASK	BIT(5)
1008c2ecf20Sopenharmony_ci#define MICB_1_EN_PULL_DOWN_EN_ENABLE	BIT(5)
1018c2ecf20Sopenharmony_ci#define MICB_1_EN_OPA_STG2_TAIL_CURR_MASK GENMASK(3, 1)
1028c2ecf20Sopenharmony_ci#define MICB_1_EN_OPA_STG2_TAIL_CURR_1_60UA	(0x4)
1038c2ecf20Sopenharmony_ci#define MICB_1_EN_PULL_UP_EN_MASK	BIT(4)
1048c2ecf20Sopenharmony_ci#define MICB_1_EN_TX3_GND_SEL_MASK	BIT(0)
1058c2ecf20Sopenharmony_ci#define MICB_1_EN_TX3_GND_SEL_TX_GND	0
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define CDC_A_MICB_1_VAL		(0xf141)
1088c2ecf20Sopenharmony_ci#define MICB_MIN_VAL 1600
1098c2ecf20Sopenharmony_ci#define MICB_STEP_SIZE 50
1108c2ecf20Sopenharmony_ci#define MICB_VOLTAGE_REGVAL(v)		(((v - MICB_MIN_VAL)/MICB_STEP_SIZE) << 3)
1118c2ecf20Sopenharmony_ci#define MICB_1_VAL_MICB_OUT_VAL_MASK	GENMASK(7, 3)
1128c2ecf20Sopenharmony_ci#define MICB_1_VAL_MICB_OUT_VAL_V2P70V	((0x16)  << 3)
1138c2ecf20Sopenharmony_ci#define MICB_1_VAL_MICB_OUT_VAL_V1P80V	((0x4)  << 3)
1148c2ecf20Sopenharmony_ci#define CDC_A_MICB_1_CTL		(0xf142)
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#define MICB_1_CTL_CFILT_REF_SEL_MASK		BIT(1)
1178c2ecf20Sopenharmony_ci#define MICB_1_CTL_CFILT_REF_SEL_HPF_REF	BIT(1)
1188c2ecf20Sopenharmony_ci#define MICB_1_CTL_EXT_PRECHARG_EN_MASK		BIT(5)
1198c2ecf20Sopenharmony_ci#define MICB_1_CTL_EXT_PRECHARG_EN_ENABLE	BIT(5)
1208c2ecf20Sopenharmony_ci#define MICB_1_CTL_INT_PRECHARG_BYP_MASK	BIT(6)
1218c2ecf20Sopenharmony_ci#define MICB_1_CTL_INT_PRECHARG_BYP_EXT_PRECHRG_SEL	BIT(6)
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define CDC_A_MICB_1_INT_RBIAS			(0xf143)
1248c2ecf20Sopenharmony_ci#define MICB_1_INT_TX1_INT_RBIAS_EN_MASK	BIT(7)
1258c2ecf20Sopenharmony_ci#define MICB_1_INT_TX1_INT_RBIAS_EN_ENABLE	BIT(7)
1268c2ecf20Sopenharmony_ci#define MICB_1_INT_TX1_INT_RBIAS_EN_DISABLE	0
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define MICB_1_INT_TX1_INT_PULLUP_EN_MASK	BIT(6)
1298c2ecf20Sopenharmony_ci#define MICB_1_INT_TX1_INT_PULLUP_EN_TX1N_TO_MICBIAS BIT(6)
1308c2ecf20Sopenharmony_ci#define MICB_1_INT_TX1_INT_PULLUP_EN_TX1N_TO_GND	0
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci#define MICB_1_INT_TX2_INT_RBIAS_EN_MASK	BIT(4)
1338c2ecf20Sopenharmony_ci#define MICB_1_INT_TX2_INT_RBIAS_EN_ENABLE	BIT(4)
1348c2ecf20Sopenharmony_ci#define MICB_1_INT_TX2_INT_RBIAS_EN_DISABLE	0
1358c2ecf20Sopenharmony_ci#define MICB_1_INT_TX2_INT_PULLUP_EN_MASK	BIT(3)
1368c2ecf20Sopenharmony_ci#define MICB_1_INT_TX2_INT_PULLUP_EN_TX1N_TO_MICBIAS BIT(3)
1378c2ecf20Sopenharmony_ci#define MICB_1_INT_TX2_INT_PULLUP_EN_TX1N_TO_GND	0
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#define MICB_1_INT_TX3_INT_RBIAS_EN_MASK	BIT(1)
1408c2ecf20Sopenharmony_ci#define MICB_1_INT_TX3_INT_RBIAS_EN_ENABLE	BIT(1)
1418c2ecf20Sopenharmony_ci#define MICB_1_INT_TX3_INT_RBIAS_EN_DISABLE	0
1428c2ecf20Sopenharmony_ci#define MICB_1_INT_TX3_INT_PULLUP_EN_MASK	BIT(0)
1438c2ecf20Sopenharmony_ci#define MICB_1_INT_TX3_INT_PULLUP_EN_TX1N_TO_MICBIAS BIT(0)
1448c2ecf20Sopenharmony_ci#define MICB_1_INT_TX3_INT_PULLUP_EN_TX1N_TO_GND	0
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci#define CDC_A_MICB_2_EN			(0xf144)
1478c2ecf20Sopenharmony_ci#define CDC_A_MICB_2_EN_ENABLE		BIT(7)
1488c2ecf20Sopenharmony_ci#define CDC_A_MICB_2_PULL_DOWN_EN_MASK	BIT(5)
1498c2ecf20Sopenharmony_ci#define CDC_A_MICB_2_PULL_DOWN_EN	BIT(5)
1508c2ecf20Sopenharmony_ci#define CDC_A_TX_1_2_ATEST_CTL_2	(0xf145)
1518c2ecf20Sopenharmony_ci#define CDC_A_MASTER_BIAS_CTL		(0xf146)
1528c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_1		(0xf147)
1538c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_L_DET_EN			BIT(7)
1548c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_GND_DET_EN			BIT(6)
1558c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_INSERTION	BIT(5)
1568c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_REMOVAL	(0)
1578c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK		BIT(5)
1588c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_SHIFT		(5)
1598c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_MIC_CLAMP_CTL_AUTO		BIT(4)
1608c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_MIC_CLAMP_CTL_MANUAL		BIT(3)
1618c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_MIC_CLAMP_CTL_MASK		GENMASK(4, 3)
1628c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_MBHC_BIAS_EN			BIT(2)
1638c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_2		(0xf150)
1648c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_HS_L_DET_PULL_UP_CTRL_I_3P0	(BIT(7) | BIT(6))
1658c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_HS_L_DET_COMPA_CTRL_V0P9_VDD	BIT(5)
1668c2ecf20Sopenharmony_ci#define CDC_A_PLUG_TYPE_MASK				GENMASK(4, 3)
1678c2ecf20Sopenharmony_ci#define CDC_A_HPHL_PLUG_TYPE_NO				BIT(4)
1688c2ecf20Sopenharmony_ci#define CDC_A_GND_PLUG_TYPE_NO				BIT(3)
1698c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_HPHL_100K_TO_GND_EN_MASK	BIT(0)
1708c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DET_CTL_HPHL_100K_TO_GND_EN		BIT(0)
1718c2ecf20Sopenharmony_ci#define CDC_A_MBHC_FSM_CTL		(0xf151)
1728c2ecf20Sopenharmony_ci#define CDC_A_MBHC_FSM_CTL_MBHC_FSM_EN			BIT(7)
1738c2ecf20Sopenharmony_ci#define CDC_A_MBHC_FSM_CTL_MBHC_FSM_EN_MASK		BIT(7)
1748c2ecf20Sopenharmony_ci#define CDC_A_MBHC_FSM_CTL_BTN_ISRC_CTRL_I_100UA	(0x3 << 4)
1758c2ecf20Sopenharmony_ci#define CDC_A_MBHC_FSM_CTL_BTN_ISRC_CTRL_MASK		GENMASK(6, 4)
1768c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DBNC_TIMER		(0xf152)
1778c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DBNC_TIMER_BTN_DBNC_T_16MS		BIT(3)
1788c2ecf20Sopenharmony_ci#define CDC_A_MBHC_DBNC_TIMER_INSREM_DBNC_T_256_MS	(0x9 << 4)
1798c2ecf20Sopenharmony_ci#define CDC_A_MBHC_BTN0_ZDET_CTL_0	(0xf153)
1808c2ecf20Sopenharmony_ci#define CDC_A_MBHC_BTN1_ZDET_CTL_1	(0xf154)
1818c2ecf20Sopenharmony_ci#define CDC_A_MBHC_BTN2_ZDET_CTL_2	(0xf155)
1828c2ecf20Sopenharmony_ci#define CDC_A_MBHC_BTN3_CTL		(0xf156)
1838c2ecf20Sopenharmony_ci#define CDC_A_MBHC_BTN4_CTL		(0xf157)
1848c2ecf20Sopenharmony_ci#define CDC_A_MBHC_BTN_VREF_FINE_SHIFT	(2)
1858c2ecf20Sopenharmony_ci#define CDC_A_MBHC_BTN_VREF_FINE_MASK	GENMASK(4, 2)
1868c2ecf20Sopenharmony_ci#define CDC_A_MBHC_BTN_VREF_COARSE_MASK	GENMASK(7, 5)
1878c2ecf20Sopenharmony_ci#define CDC_A_MBHC_BTN_VREF_COARSE_SHIFT (5)
1888c2ecf20Sopenharmony_ci#define CDC_A_MBHC_BTN_VREF_MASK	(CDC_A_MBHC_BTN_VREF_COARSE_MASK | \
1898c2ecf20Sopenharmony_ci					CDC_A_MBHC_BTN_VREF_FINE_MASK)
1908c2ecf20Sopenharmony_ci#define CDC_A_MBHC_RESULT_1		(0xf158)
1918c2ecf20Sopenharmony_ci#define CDC_A_MBHC_RESULT_1_BTN_RESULT_MASK	GENMASK(4, 0)
1928c2ecf20Sopenharmony_ci#define CDC_A_TX_1_EN			(0xf160)
1938c2ecf20Sopenharmony_ci#define CDC_A_TX_2_EN			(0xf161)
1948c2ecf20Sopenharmony_ci#define CDC_A_TX_1_2_TEST_CTL_1		(0xf162)
1958c2ecf20Sopenharmony_ci#define CDC_A_TX_1_2_TEST_CTL_2		(0xf163)
1968c2ecf20Sopenharmony_ci#define CDC_A_TX_1_2_ATEST_CTL		(0xf164)
1978c2ecf20Sopenharmony_ci#define CDC_A_TX_1_2_OPAMP_BIAS		(0xf165)
1988c2ecf20Sopenharmony_ci#define CDC_A_TX_3_EN			(0xf167)
1998c2ecf20Sopenharmony_ci#define CDC_A_NCP_EN			(0xf180)
2008c2ecf20Sopenharmony_ci#define CDC_A_NCP_CLK			(0xf181)
2018c2ecf20Sopenharmony_ci#define CDC_A_NCP_FBCTRL		(0xf183)
2028c2ecf20Sopenharmony_ci#define CDC_A_NCP_FBCTRL_FB_CLK_INV_MASK	BIT(5)
2038c2ecf20Sopenharmony_ci#define CDC_A_NCP_FBCTRL_FB_CLK_INV		BIT(5)
2048c2ecf20Sopenharmony_ci#define CDC_A_NCP_BIAS			(0xf184)
2058c2ecf20Sopenharmony_ci#define CDC_A_NCP_VCTRL			(0xf185)
2068c2ecf20Sopenharmony_ci#define CDC_A_NCP_TEST			(0xf186)
2078c2ecf20Sopenharmony_ci#define CDC_A_NCP_CLIM_ADDR		(0xf187)
2088c2ecf20Sopenharmony_ci#define CDC_A_RX_CLOCK_DIVIDER		(0xf190)
2098c2ecf20Sopenharmony_ci#define CDC_A_RX_COM_OCP_CTL		(0xf191)
2108c2ecf20Sopenharmony_ci#define CDC_A_RX_COM_OCP_COUNT		(0xf192)
2118c2ecf20Sopenharmony_ci#define CDC_A_RX_COM_BIAS_DAC		(0xf193)
2128c2ecf20Sopenharmony_ci#define RX_COM_BIAS_DAC_RX_BIAS_EN_MASK		BIT(7)
2138c2ecf20Sopenharmony_ci#define RX_COM_BIAS_DAC_RX_BIAS_EN_ENABLE	BIT(7)
2148c2ecf20Sopenharmony_ci#define RX_COM_BIAS_DAC_DAC_REF_EN_MASK		BIT(0)
2158c2ecf20Sopenharmony_ci#define RX_COM_BIAS_DAC_DAC_REF_EN_ENABLE	BIT(0)
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci#define CDC_A_RX_HPH_BIAS_PA		(0xf194)
2188c2ecf20Sopenharmony_ci#define CDC_A_RX_HPH_BIAS_LDO_OCP	(0xf195)
2198c2ecf20Sopenharmony_ci#define CDC_A_RX_HPH_BIAS_CNP		(0xf196)
2208c2ecf20Sopenharmony_ci#define CDC_A_RX_HPH_CNP_EN		(0xf197)
2218c2ecf20Sopenharmony_ci#define CDC_A_RX_HPH_L_PA_DAC_CTL	(0xf19B)
2228c2ecf20Sopenharmony_ci#define RX_HPA_L_PA_DAC_CTL_DATA_RESET_MASK	BIT(1)
2238c2ecf20Sopenharmony_ci#define RX_HPA_L_PA_DAC_CTL_DATA_RESET_RESET	BIT(1)
2248c2ecf20Sopenharmony_ci#define CDC_A_RX_HPH_R_PA_DAC_CTL	(0xf19D)
2258c2ecf20Sopenharmony_ci#define RX_HPH_R_PA_DAC_CTL_DATA_RESET	BIT(1)
2268c2ecf20Sopenharmony_ci#define RX_HPH_R_PA_DAC_CTL_DATA_RESET_MASK BIT(1)
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci#define CDC_A_RX_EAR_CTL			(0xf19E)
2298c2ecf20Sopenharmony_ci#define RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK		BIT(0)
2308c2ecf20Sopenharmony_ci#define RX_EAR_CTL_SPK_VBAT_LDO_EN_ENABLE	BIT(0)
2318c2ecf20Sopenharmony_ci#define RX_EAR_CTL_PA_EAR_PA_EN_MASK		BIT(6)
2328c2ecf20Sopenharmony_ci#define RX_EAR_CTL_PA_EAR_PA_EN_ENABLE		BIT(6)
2338c2ecf20Sopenharmony_ci#define RX_EAR_CTL_PA_SEL_MASK			BIT(7)
2348c2ecf20Sopenharmony_ci#define RX_EAR_CTL_PA_SEL			BIT(7)
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci#define CDC_A_SPKR_DAC_CTL		(0xf1B0)
2378c2ecf20Sopenharmony_ci#define SPKR_DAC_CTL_DAC_RESET_MASK	BIT(4)
2388c2ecf20Sopenharmony_ci#define SPKR_DAC_CTL_DAC_RESET_NORMAL	0
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci#define CDC_A_SPKR_DRV_CTL		(0xf1B2)
2418c2ecf20Sopenharmony_ci#define SPKR_DRV_CTL_DEF_MASK		0xEF
2428c2ecf20Sopenharmony_ci#define SPKR_DRV_CLASSD_PA_EN_MASK	BIT(7)
2438c2ecf20Sopenharmony_ci#define SPKR_DRV_CLASSD_PA_EN_ENABLE	BIT(7)
2448c2ecf20Sopenharmony_ci#define SPKR_DRV_CAL_EN			BIT(6)
2458c2ecf20Sopenharmony_ci#define SPKR_DRV_SETTLE_EN		BIT(5)
2468c2ecf20Sopenharmony_ci#define SPKR_DRV_FW_EN			BIT(3)
2478c2ecf20Sopenharmony_ci#define SPKR_DRV_BOOST_SET		BIT(2)
2488c2ecf20Sopenharmony_ci#define SPKR_DRV_CMFB_SET		BIT(1)
2498c2ecf20Sopenharmony_ci#define SPKR_DRV_GAIN_SET		BIT(0)
2508c2ecf20Sopenharmony_ci#define SPKR_DRV_CTL_DEF_VAL (SPKR_DRV_CLASSD_PA_EN_ENABLE | \
2518c2ecf20Sopenharmony_ci		SPKR_DRV_CAL_EN | SPKR_DRV_SETTLE_EN | \
2528c2ecf20Sopenharmony_ci		SPKR_DRV_FW_EN | SPKR_DRV_BOOST_SET | \
2538c2ecf20Sopenharmony_ci		SPKR_DRV_CMFB_SET | SPKR_DRV_GAIN_SET)
2548c2ecf20Sopenharmony_ci#define CDC_A_SPKR_OCP_CTL		(0xf1B4)
2558c2ecf20Sopenharmony_ci#define CDC_A_SPKR_PWRSTG_CTL		(0xf1B5)
2568c2ecf20Sopenharmony_ci#define SPKR_PWRSTG_CTL_DAC_EN_MASK	BIT(0)
2578c2ecf20Sopenharmony_ci#define SPKR_PWRSTG_CTL_DAC_EN		BIT(0)
2588c2ecf20Sopenharmony_ci#define SPKR_PWRSTG_CTL_MASK		0xE0
2598c2ecf20Sopenharmony_ci#define SPKR_PWRSTG_CTL_BBM_MASK	BIT(7)
2608c2ecf20Sopenharmony_ci#define SPKR_PWRSTG_CTL_BBM_EN		BIT(7)
2618c2ecf20Sopenharmony_ci#define SPKR_PWRSTG_CTL_HBRDGE_EN_MASK	BIT(6)
2628c2ecf20Sopenharmony_ci#define SPKR_PWRSTG_CTL_HBRDGE_EN	BIT(6)
2638c2ecf20Sopenharmony_ci#define SPKR_PWRSTG_CTL_CLAMP_EN_MASK	BIT(5)
2648c2ecf20Sopenharmony_ci#define SPKR_PWRSTG_CTL_CLAMP_EN	BIT(5)
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci#define CDC_A_SPKR_DRV_DBG		(0xf1B7)
2678c2ecf20Sopenharmony_ci#define CDC_A_CURRENT_LIMIT		(0xf1C0)
2688c2ecf20Sopenharmony_ci#define CDC_A_BOOST_EN_CTL		(0xf1C3)
2698c2ecf20Sopenharmony_ci#define CDC_A_SLOPE_COMP_IP_ZERO	(0xf1C4)
2708c2ecf20Sopenharmony_ci#define CDC_A_SEC_ACCESS		(0xf1D0)
2718c2ecf20Sopenharmony_ci#define CDC_A_PERPH_RESET_CTL3		(0xf1DA)
2728c2ecf20Sopenharmony_ci#define CDC_A_PERPH_RESET_CTL4		(0xf1DB)
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_ci#define MSM8916_WCD_ANALOG_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
2758c2ecf20Sopenharmony_ci			SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_48000)
2768c2ecf20Sopenharmony_ci#define MSM8916_WCD_ANALOG_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
2778c2ecf20Sopenharmony_ci				    SNDRV_PCM_FMTBIT_S32_LE)
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_cistatic int btn_mask = SND_JACK_BTN_0 | SND_JACK_BTN_1 |
2808c2ecf20Sopenharmony_ci	       SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_BTN_4;
2818c2ecf20Sopenharmony_cistatic int hs_jack_mask = SND_JACK_HEADPHONE | SND_JACK_HEADSET;
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_cistatic const char * const supply_names[] = {
2848c2ecf20Sopenharmony_ci	"vdd-cdc-io",
2858c2ecf20Sopenharmony_ci	"vdd-cdc-tx-rx-cx",
2868c2ecf20Sopenharmony_ci};
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci#define MBHC_MAX_BUTTONS	(5)
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_cistruct pm8916_wcd_analog_priv {
2918c2ecf20Sopenharmony_ci	u16 pmic_rev;
2928c2ecf20Sopenharmony_ci	u16 codec_version;
2938c2ecf20Sopenharmony_ci	bool	mbhc_btn_enabled;
2948c2ecf20Sopenharmony_ci	/* special event to detect accessory type */
2958c2ecf20Sopenharmony_ci	int	mbhc_btn0_released;
2968c2ecf20Sopenharmony_ci	bool	detect_accessory_type;
2978c2ecf20Sopenharmony_ci	struct clk *mclk;
2988c2ecf20Sopenharmony_ci	struct snd_soc_component *component;
2998c2ecf20Sopenharmony_ci	struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
3008c2ecf20Sopenharmony_ci	struct snd_soc_jack *jack;
3018c2ecf20Sopenharmony_ci	bool hphl_jack_type_normally_open;
3028c2ecf20Sopenharmony_ci	bool gnd_jack_type_normally_open;
3038c2ecf20Sopenharmony_ci	/* Voltage threshold when internal current source of 100uA is used */
3048c2ecf20Sopenharmony_ci	u32 vref_btn_cs[MBHC_MAX_BUTTONS];
3058c2ecf20Sopenharmony_ci	/* Voltage threshold when microphone bias is ON */
3068c2ecf20Sopenharmony_ci	u32 vref_btn_micb[MBHC_MAX_BUTTONS];
3078c2ecf20Sopenharmony_ci	unsigned int micbias1_cap_mode;
3088c2ecf20Sopenharmony_ci	unsigned int micbias2_cap_mode;
3098c2ecf20Sopenharmony_ci	unsigned int micbias_mv;
3108c2ecf20Sopenharmony_ci};
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_cistatic const char *const adc2_mux_text[] = { "ZERO", "INP2", "INP3" };
3138c2ecf20Sopenharmony_cistatic const char *const rdac2_mux_text[] = { "RX1", "RX2" };
3148c2ecf20Sopenharmony_cistatic const char *const hph_text[] = { "ZERO", "Switch", };
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_cistatic const struct soc_enum hph_enum = SOC_ENUM_SINGLE_VIRT(
3178c2ecf20Sopenharmony_ci					ARRAY_SIZE(hph_text), hph_text);
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new ear_mux = SOC_DAPM_ENUM("EAR_S", hph_enum);
3208c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hphl_mux = SOC_DAPM_ENUM("HPHL", hph_enum);
3218c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new hphr_mux = SOC_DAPM_ENUM("HPHR", hph_enum);
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci/* ADC2 MUX */
3248c2ecf20Sopenharmony_cistatic const struct soc_enum adc2_enum = SOC_ENUM_SINGLE_VIRT(
3258c2ecf20Sopenharmony_ci			ARRAY_SIZE(adc2_mux_text), adc2_mux_text);
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci/* RDAC2 MUX */
3288c2ecf20Sopenharmony_cistatic const struct soc_enum rdac2_mux_enum = SOC_ENUM_SINGLE(
3298c2ecf20Sopenharmony_ci			CDC_D_CDC_CONN_HPHR_DAC_CTL, 0, 2, rdac2_mux_text);
3308c2ecf20Sopenharmony_ci
3318c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new spkr_switch[] = {
3328c2ecf20Sopenharmony_ci	SOC_DAPM_SINGLE("Switch", CDC_A_SPKR_DAC_CTL, 7, 1, 0)
3338c2ecf20Sopenharmony_ci};
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new rdac2_mux = SOC_DAPM_ENUM(
3368c2ecf20Sopenharmony_ci					"RDAC2 MUX Mux", rdac2_mux_enum);
3378c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new tx_adc2_mux = SOC_DAPM_ENUM(
3388c2ecf20Sopenharmony_ci					"ADC2 MUX Mux", adc2_enum);
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci/* Analog Gain control 0 dB to +24 dB in 6 dB steps */
3418c2ecf20Sopenharmony_cistatic const DECLARE_TLV_DB_SCALE(analog_gain, 0, 600, 0);
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new pm8916_wcd_analog_snd_controls[] = {
3448c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ADC1 Volume", CDC_A_TX_1_EN, 3, 8, 0, analog_gain),
3458c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ADC2 Volume", CDC_A_TX_2_EN, 3, 8, 0, analog_gain),
3468c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ADC3 Volume", CDC_A_TX_3_EN, 3, 8, 0, analog_gain),
3478c2ecf20Sopenharmony_ci};
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_cistatic void pm8916_wcd_analog_micbias_enable(struct snd_soc_component *component)
3508c2ecf20Sopenharmony_ci{
3518c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *wcd = snd_soc_component_get_drvdata(component);
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, CDC_A_MICB_1_CTL,
3548c2ecf20Sopenharmony_ci			    MICB_1_CTL_EXT_PRECHARG_EN_MASK |
3558c2ecf20Sopenharmony_ci			    MICB_1_CTL_INT_PRECHARG_BYP_MASK,
3568c2ecf20Sopenharmony_ci			    MICB_1_CTL_INT_PRECHARG_BYP_EXT_PRECHRG_SEL
3578c2ecf20Sopenharmony_ci			    | MICB_1_CTL_EXT_PRECHARG_EN_ENABLE);
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci	if (wcd->micbias_mv) {
3608c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_MICB_1_VAL,
3618c2ecf20Sopenharmony_ci				    MICB_1_VAL_MICB_OUT_VAL_MASK,
3628c2ecf20Sopenharmony_ci				    MICB_VOLTAGE_REGVAL(wcd->micbias_mv));
3638c2ecf20Sopenharmony_ci		/*
3648c2ecf20Sopenharmony_ci		 * Special headset needs MICBIAS as 2.7V so wait for
3658c2ecf20Sopenharmony_ci		 * 50 msec for the MICBIAS to reach 2.7 volts.
3668c2ecf20Sopenharmony_ci		 */
3678c2ecf20Sopenharmony_ci		if (wcd->micbias_mv >= 2700)
3688c2ecf20Sopenharmony_ci			msleep(50);
3698c2ecf20Sopenharmony_ci	}
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, CDC_A_MICB_1_CTL,
3728c2ecf20Sopenharmony_ci			    MICB_1_CTL_EXT_PRECHARG_EN_MASK |
3738c2ecf20Sopenharmony_ci			    MICB_1_CTL_INT_PRECHARG_BYP_MASK, 0);
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci}
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_enable_micbias(struct snd_soc_component *component,
3788c2ecf20Sopenharmony_ci					    int event, unsigned int cap_mode)
3798c2ecf20Sopenharmony_ci{
3808c2ecf20Sopenharmony_ci	switch (event) {
3818c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
3828c2ecf20Sopenharmony_ci		pm8916_wcd_analog_micbias_enable(component);
3838c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_MICB_1_EN,
3848c2ecf20Sopenharmony_ci				    MICB_1_EN_BYP_CAP_MASK, cap_mode);
3858c2ecf20Sopenharmony_ci		break;
3868c2ecf20Sopenharmony_ci	}
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	return 0;
3898c2ecf20Sopenharmony_ci}
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_enable_micbias_int(struct snd_soc_dapm_widget *w,
3928c2ecf20Sopenharmony_ci						struct snd_kcontrol *kcontrol,
3938c2ecf20Sopenharmony_ci						int event)
3948c2ecf20Sopenharmony_ci{
3958c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	switch (event) {
3988c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
3998c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_MICB_1_EN,
4008c2ecf20Sopenharmony_ci				    MICB_1_EN_OPA_STG2_TAIL_CURR_MASK,
4018c2ecf20Sopenharmony_ci				    MICB_1_EN_OPA_STG2_TAIL_CURR_1_60UA);
4028c2ecf20Sopenharmony_ci		break;
4038c2ecf20Sopenharmony_ci	}
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	return 0;
4068c2ecf20Sopenharmony_ci}
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_enable_micbias1(struct snd_soc_dapm_widget *w,
4098c2ecf20Sopenharmony_ci					     struct snd_kcontrol *kcontrol,
4108c2ecf20Sopenharmony_ci					     int event)
4118c2ecf20Sopenharmony_ci{
4128c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
4138c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *wcd = snd_soc_component_get_drvdata(component);
4148c2ecf20Sopenharmony_ci
4158c2ecf20Sopenharmony_ci	return pm8916_wcd_analog_enable_micbias(component, event,
4168c2ecf20Sopenharmony_ci						wcd->micbias1_cap_mode);
4178c2ecf20Sopenharmony_ci}
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_enable_micbias2(struct snd_soc_dapm_widget *w,
4208c2ecf20Sopenharmony_ci					     struct snd_kcontrol *kcontrol,
4218c2ecf20Sopenharmony_ci					     int event)
4228c2ecf20Sopenharmony_ci{
4238c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
4248c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *wcd = snd_soc_component_get_drvdata(component);
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci	return pm8916_wcd_analog_enable_micbias(component, event,
4278c2ecf20Sopenharmony_ci						wcd->micbias2_cap_mode);
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci}
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_cistatic int pm8916_mbhc_configure_bias(struct pm8916_wcd_analog_priv *priv,
4328c2ecf20Sopenharmony_ci				      bool micbias2_enabled)
4338c2ecf20Sopenharmony_ci{
4348c2ecf20Sopenharmony_ci	struct snd_soc_component *component = priv->component;
4358c2ecf20Sopenharmony_ci	u32 coarse, fine, reg_val, reg_addr;
4368c2ecf20Sopenharmony_ci	int *vrefs, i;
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci	if (!micbias2_enabled) { /* use internal 100uA Current source */
4398c2ecf20Sopenharmony_ci		/* Enable internal 2.2k Internal Rbias Resistor */
4408c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_MICB_1_INT_RBIAS,
4418c2ecf20Sopenharmony_ci				    MICB_1_INT_TX2_INT_RBIAS_EN_MASK,
4428c2ecf20Sopenharmony_ci				    MICB_1_INT_TX2_INT_RBIAS_EN_ENABLE);
4438c2ecf20Sopenharmony_ci		/* Remove pull down on MIC BIAS2 */
4448c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_MICB_2_EN,
4458c2ecf20Sopenharmony_ci				   CDC_A_MICB_2_PULL_DOWN_EN_MASK,
4468c2ecf20Sopenharmony_ci				   0);
4478c2ecf20Sopenharmony_ci		/* enable 100uA internal current source */
4488c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_MBHC_FSM_CTL,
4498c2ecf20Sopenharmony_ci				    CDC_A_MBHC_FSM_CTL_BTN_ISRC_CTRL_MASK,
4508c2ecf20Sopenharmony_ci				    CDC_A_MBHC_FSM_CTL_BTN_ISRC_CTRL_I_100UA);
4518c2ecf20Sopenharmony_ci	}
4528c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, CDC_A_MBHC_FSM_CTL,
4538c2ecf20Sopenharmony_ci			CDC_A_MBHC_FSM_CTL_MBHC_FSM_EN_MASK,
4548c2ecf20Sopenharmony_ci			CDC_A_MBHC_FSM_CTL_MBHC_FSM_EN);
4558c2ecf20Sopenharmony_ci
4568c2ecf20Sopenharmony_ci	if (micbias2_enabled)
4578c2ecf20Sopenharmony_ci		vrefs = &priv->vref_btn_micb[0];
4588c2ecf20Sopenharmony_ci	else
4598c2ecf20Sopenharmony_ci		vrefs = &priv->vref_btn_cs[0];
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci	/* program vref ranges for all the buttons */
4628c2ecf20Sopenharmony_ci	reg_addr = CDC_A_MBHC_BTN0_ZDET_CTL_0;
4638c2ecf20Sopenharmony_ci	for (i = 0; i <  MBHC_MAX_BUTTONS; i++) {
4648c2ecf20Sopenharmony_ci		/* split mv in to coarse parts of 100mv & fine parts of 12mv */
4658c2ecf20Sopenharmony_ci		coarse = (vrefs[i] / 100);
4668c2ecf20Sopenharmony_ci		fine = ((vrefs[i] % 100) / 12);
4678c2ecf20Sopenharmony_ci		reg_val = (coarse << CDC_A_MBHC_BTN_VREF_COARSE_SHIFT) |
4688c2ecf20Sopenharmony_ci			 (fine << CDC_A_MBHC_BTN_VREF_FINE_SHIFT);
4698c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, reg_addr,
4708c2ecf20Sopenharmony_ci			       CDC_A_MBHC_BTN_VREF_MASK,
4718c2ecf20Sopenharmony_ci			       reg_val);
4728c2ecf20Sopenharmony_ci		reg_addr++;
4738c2ecf20Sopenharmony_ci	}
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci	return 0;
4768c2ecf20Sopenharmony_ci}
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_cistatic void pm8916_wcd_setup_mbhc(struct pm8916_wcd_analog_priv *wcd)
4798c2ecf20Sopenharmony_ci{
4808c2ecf20Sopenharmony_ci	struct snd_soc_component *component = wcd->component;
4818c2ecf20Sopenharmony_ci	bool micbias_enabled = false;
4828c2ecf20Sopenharmony_ci	u32 plug_type = 0;
4838c2ecf20Sopenharmony_ci	u32 int_en_mask;
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci	snd_soc_component_write(component, CDC_A_MBHC_DET_CTL_1,
4868c2ecf20Sopenharmony_ci		      CDC_A_MBHC_DET_CTL_L_DET_EN |
4878c2ecf20Sopenharmony_ci		      CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_INSERTION |
4888c2ecf20Sopenharmony_ci		      CDC_A_MBHC_DET_CTL_MIC_CLAMP_CTL_AUTO |
4898c2ecf20Sopenharmony_ci		      CDC_A_MBHC_DET_CTL_MBHC_BIAS_EN);
4908c2ecf20Sopenharmony_ci
4918c2ecf20Sopenharmony_ci	if (wcd->hphl_jack_type_normally_open)
4928c2ecf20Sopenharmony_ci		plug_type |= CDC_A_HPHL_PLUG_TYPE_NO;
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci	if (wcd->gnd_jack_type_normally_open)
4958c2ecf20Sopenharmony_ci		plug_type |= CDC_A_GND_PLUG_TYPE_NO;
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci	snd_soc_component_write(component, CDC_A_MBHC_DET_CTL_2,
4988c2ecf20Sopenharmony_ci		      CDC_A_MBHC_DET_CTL_HS_L_DET_PULL_UP_CTRL_I_3P0 |
4998c2ecf20Sopenharmony_ci		      CDC_A_MBHC_DET_CTL_HS_L_DET_COMPA_CTRL_V0P9_VDD |
5008c2ecf20Sopenharmony_ci		      plug_type |
5018c2ecf20Sopenharmony_ci		      CDC_A_MBHC_DET_CTL_HPHL_100K_TO_GND_EN);
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci	snd_soc_component_write(component, CDC_A_MBHC_DBNC_TIMER,
5058c2ecf20Sopenharmony_ci		      CDC_A_MBHC_DBNC_TIMER_INSREM_DBNC_T_256_MS |
5068c2ecf20Sopenharmony_ci		      CDC_A_MBHC_DBNC_TIMER_BTN_DBNC_T_16MS);
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci	/* enable MBHC clock */
5098c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, CDC_D_CDC_DIG_CLK_CTL,
5108c2ecf20Sopenharmony_ci			    DIG_CLK_CTL_D_MBHC_CLK_EN_MASK,
5118c2ecf20Sopenharmony_ci			    DIG_CLK_CTL_D_MBHC_CLK_EN);
5128c2ecf20Sopenharmony_ci
5138c2ecf20Sopenharmony_ci	if (snd_soc_component_read(component, CDC_A_MICB_2_EN) & CDC_A_MICB_2_EN_ENABLE)
5148c2ecf20Sopenharmony_ci		micbias_enabled = true;
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci	pm8916_mbhc_configure_bias(wcd, micbias_enabled);
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci	int_en_mask = MBHC_SWITCH_INT;
5198c2ecf20Sopenharmony_ci	if (wcd->mbhc_btn_enabled)
5208c2ecf20Sopenharmony_ci		int_en_mask |= MBHC_BUTTON_PRESS_DET | MBHC_BUTTON_RELEASE_DET;
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, CDC_D_INT_EN_CLR, int_en_mask, 0);
5238c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, CDC_D_INT_EN_SET, int_en_mask, int_en_mask);
5248c2ecf20Sopenharmony_ci	wcd->mbhc_btn0_released = false;
5258c2ecf20Sopenharmony_ci	wcd->detect_accessory_type = true;
5268c2ecf20Sopenharmony_ci}
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_enable_micbias_int2(struct
5298c2ecf20Sopenharmony_ci						  snd_soc_dapm_widget
5308c2ecf20Sopenharmony_ci						  *w, struct snd_kcontrol
5318c2ecf20Sopenharmony_ci						  *kcontrol, int event)
5328c2ecf20Sopenharmony_ci{
5338c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
5348c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *wcd = snd_soc_component_get_drvdata(component);
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci	switch (event) {
5378c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
5388c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_MICB_2_EN,
5398c2ecf20Sopenharmony_ci					      CDC_A_MICB_2_PULL_DOWN_EN_MASK, 0);
5408c2ecf20Sopenharmony_ci		break;
5418c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
5428c2ecf20Sopenharmony_ci		pm8916_mbhc_configure_bias(wcd, true);
5438c2ecf20Sopenharmony_ci		break;
5448c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
5458c2ecf20Sopenharmony_ci		pm8916_mbhc_configure_bias(wcd, false);
5468c2ecf20Sopenharmony_ci		break;
5478c2ecf20Sopenharmony_ci	}
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci	return pm8916_wcd_analog_enable_micbias_int(w, kcontrol, event);
5508c2ecf20Sopenharmony_ci}
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_enable_adc(struct snd_soc_dapm_widget *w,
5538c2ecf20Sopenharmony_ci					 struct snd_kcontrol *kcontrol,
5548c2ecf20Sopenharmony_ci					 int event)
5558c2ecf20Sopenharmony_ci{
5568c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
5578c2ecf20Sopenharmony_ci	u16 adc_reg = CDC_A_TX_1_2_TEST_CTL_2;
5588c2ecf20Sopenharmony_ci	u8 init_bit_shift;
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci	if (w->reg == CDC_A_TX_1_EN)
5618c2ecf20Sopenharmony_ci		init_bit_shift = 5;
5628c2ecf20Sopenharmony_ci	else
5638c2ecf20Sopenharmony_ci		init_bit_shift = 4;
5648c2ecf20Sopenharmony_ci
5658c2ecf20Sopenharmony_ci	switch (event) {
5668c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
5678c2ecf20Sopenharmony_ci		if (w->reg == CDC_A_TX_2_EN)
5688c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, CDC_A_MICB_1_CTL,
5698c2ecf20Sopenharmony_ci					    MICB_1_CTL_CFILT_REF_SEL_MASK,
5708c2ecf20Sopenharmony_ci					    MICB_1_CTL_CFILT_REF_SEL_HPF_REF);
5718c2ecf20Sopenharmony_ci		/*
5728c2ecf20Sopenharmony_ci		 * Add delay of 10 ms to give sufficient time for the voltage
5738c2ecf20Sopenharmony_ci		 * to shoot up and settle so that the txfe init does not
5748c2ecf20Sopenharmony_ci		 * happen when the input voltage is changing too much.
5758c2ecf20Sopenharmony_ci		 */
5768c2ecf20Sopenharmony_ci		usleep_range(10000, 10010);
5778c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, adc_reg, 1 << init_bit_shift,
5788c2ecf20Sopenharmony_ci				    1 << init_bit_shift);
5798c2ecf20Sopenharmony_ci		switch (w->reg) {
5808c2ecf20Sopenharmony_ci		case CDC_A_TX_1_EN:
5818c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, CDC_D_CDC_CONN_TX1_CTL,
5828c2ecf20Sopenharmony_ci					    CONN_TX1_SERIAL_TX1_MUX,
5838c2ecf20Sopenharmony_ci					    CONN_TX1_SERIAL_TX1_ADC_1);
5848c2ecf20Sopenharmony_ci			break;
5858c2ecf20Sopenharmony_ci		case CDC_A_TX_2_EN:
5868c2ecf20Sopenharmony_ci		case CDC_A_TX_3_EN:
5878c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, CDC_D_CDC_CONN_TX2_CTL,
5888c2ecf20Sopenharmony_ci					    CONN_TX2_SERIAL_TX2_MUX,
5898c2ecf20Sopenharmony_ci					    CONN_TX2_SERIAL_TX2_ADC_2);
5908c2ecf20Sopenharmony_ci			break;
5918c2ecf20Sopenharmony_ci		}
5928c2ecf20Sopenharmony_ci		break;
5938c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
5948c2ecf20Sopenharmony_ci		/*
5958c2ecf20Sopenharmony_ci		 * Add delay of 12 ms before deasserting the init
5968c2ecf20Sopenharmony_ci		 * to reduce the tx pop
5978c2ecf20Sopenharmony_ci		 */
5988c2ecf20Sopenharmony_ci		usleep_range(12000, 12010);
5998c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, adc_reg, 1 << init_bit_shift, 0x00);
6008c2ecf20Sopenharmony_ci		break;
6018c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
6028c2ecf20Sopenharmony_ci		switch (w->reg) {
6038c2ecf20Sopenharmony_ci		case CDC_A_TX_1_EN:
6048c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, CDC_D_CDC_CONN_TX1_CTL,
6058c2ecf20Sopenharmony_ci					    CONN_TX1_SERIAL_TX1_MUX,
6068c2ecf20Sopenharmony_ci					    CONN_TX1_SERIAL_TX1_ZERO);
6078c2ecf20Sopenharmony_ci			break;
6088c2ecf20Sopenharmony_ci		case CDC_A_TX_2_EN:
6098c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, CDC_A_MICB_1_CTL,
6108c2ecf20Sopenharmony_ci					    MICB_1_CTL_CFILT_REF_SEL_MASK, 0);
6118c2ecf20Sopenharmony_ci			fallthrough;
6128c2ecf20Sopenharmony_ci		case CDC_A_TX_3_EN:
6138c2ecf20Sopenharmony_ci			snd_soc_component_update_bits(component, CDC_D_CDC_CONN_TX2_CTL,
6148c2ecf20Sopenharmony_ci					    CONN_TX2_SERIAL_TX2_MUX,
6158c2ecf20Sopenharmony_ci					    CONN_TX2_SERIAL_TX2_ZERO);
6168c2ecf20Sopenharmony_ci			break;
6178c2ecf20Sopenharmony_ci		}
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_ci		break;
6218c2ecf20Sopenharmony_ci	}
6228c2ecf20Sopenharmony_ci	return 0;
6238c2ecf20Sopenharmony_ci}
6248c2ecf20Sopenharmony_ci
6258c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_enable_spk_pa(struct snd_soc_dapm_widget *w,
6268c2ecf20Sopenharmony_ci					    struct snd_kcontrol *kcontrol,
6278c2ecf20Sopenharmony_ci					    int event)
6288c2ecf20Sopenharmony_ci{
6298c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
6308c2ecf20Sopenharmony_ci
6318c2ecf20Sopenharmony_ci	switch (event) {
6328c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
6338c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
6348c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_DAC_EN_MASK |
6358c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_BBM_MASK |
6368c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_HBRDGE_EN_MASK |
6378c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_CLAMP_EN_MASK,
6388c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_DAC_EN|
6398c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_BBM_EN |
6408c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_HBRDGE_EN |
6418c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_CLAMP_EN);
6428c2ecf20Sopenharmony_ci
6438c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
6448c2ecf20Sopenharmony_ci				    RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK,
6458c2ecf20Sopenharmony_ci				    RX_EAR_CTL_SPK_VBAT_LDO_EN_ENABLE);
6468c2ecf20Sopenharmony_ci		break;
6478c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
6488c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_SPKR_DRV_CTL,
6498c2ecf20Sopenharmony_ci				    SPKR_DRV_CTL_DEF_MASK,
6508c2ecf20Sopenharmony_ci				    SPKR_DRV_CTL_DEF_VAL);
6518c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, w->reg,
6528c2ecf20Sopenharmony_ci				    SPKR_DRV_CLASSD_PA_EN_MASK,
6538c2ecf20Sopenharmony_ci				    SPKR_DRV_CLASSD_PA_EN_ENABLE);
6548c2ecf20Sopenharmony_ci		break;
6558c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
6568c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_SPKR_PWRSTG_CTL,
6578c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_DAC_EN_MASK|
6588c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_BBM_MASK |
6598c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_HBRDGE_EN_MASK |
6608c2ecf20Sopenharmony_ci				    SPKR_PWRSTG_CTL_CLAMP_EN_MASK, 0);
6618c2ecf20Sopenharmony_ci
6628c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_SPKR_DAC_CTL,
6638c2ecf20Sopenharmony_ci				    SPKR_DAC_CTL_DAC_RESET_MASK,
6648c2ecf20Sopenharmony_ci				    SPKR_DAC_CTL_DAC_RESET_NORMAL);
6658c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
6668c2ecf20Sopenharmony_ci				    RX_EAR_CTL_SPK_VBAT_LDO_EN_MASK, 0);
6678c2ecf20Sopenharmony_ci		break;
6688c2ecf20Sopenharmony_ci	}
6698c2ecf20Sopenharmony_ci	return 0;
6708c2ecf20Sopenharmony_ci}
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_enable_ear_pa(struct snd_soc_dapm_widget *w,
6738c2ecf20Sopenharmony_ci					    struct snd_kcontrol *kcontrol,
6748c2ecf20Sopenharmony_ci					    int event)
6758c2ecf20Sopenharmony_ci{
6768c2ecf20Sopenharmony_ci	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci	switch (event) {
6798c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_PRE_PMU:
6808c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
6818c2ecf20Sopenharmony_ci				    RX_EAR_CTL_PA_SEL_MASK, RX_EAR_CTL_PA_SEL);
6828c2ecf20Sopenharmony_ci		break;
6838c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMU:
6848c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
6858c2ecf20Sopenharmony_ci				    RX_EAR_CTL_PA_EAR_PA_EN_MASK,
6868c2ecf20Sopenharmony_ci				    RX_EAR_CTL_PA_EAR_PA_EN_ENABLE);
6878c2ecf20Sopenharmony_ci		break;
6888c2ecf20Sopenharmony_ci	case SND_SOC_DAPM_POST_PMD:
6898c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
6908c2ecf20Sopenharmony_ci				    RX_EAR_CTL_PA_EAR_PA_EN_MASK, 0);
6918c2ecf20Sopenharmony_ci		/* Delay to reduce ear turn off pop */
6928c2ecf20Sopenharmony_ci		usleep_range(7000, 7100);
6938c2ecf20Sopenharmony_ci		snd_soc_component_update_bits(component, CDC_A_RX_EAR_CTL,
6948c2ecf20Sopenharmony_ci				    RX_EAR_CTL_PA_SEL_MASK, 0);
6958c2ecf20Sopenharmony_ci		break;
6968c2ecf20Sopenharmony_ci	}
6978c2ecf20Sopenharmony_ci	return 0;
6988c2ecf20Sopenharmony_ci}
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_cistatic const struct reg_default wcd_reg_defaults_2_0[] = {
7018c2ecf20Sopenharmony_ci	{CDC_A_RX_COM_OCP_CTL, 0xD1},
7028c2ecf20Sopenharmony_ci	{CDC_A_RX_COM_OCP_COUNT, 0xFF},
7038c2ecf20Sopenharmony_ci	{CDC_D_SEC_ACCESS, 0xA5},
7048c2ecf20Sopenharmony_ci	{CDC_D_PERPH_RESET_CTL3, 0x0F},
7058c2ecf20Sopenharmony_ci	{CDC_A_TX_1_2_OPAMP_BIAS, 0x4F},
7068c2ecf20Sopenharmony_ci	{CDC_A_NCP_FBCTRL, 0x28},
7078c2ecf20Sopenharmony_ci	{CDC_A_SPKR_DRV_CTL, 0x69},
7088c2ecf20Sopenharmony_ci	{CDC_A_SPKR_DRV_DBG, 0x01},
7098c2ecf20Sopenharmony_ci	{CDC_A_BOOST_EN_CTL, 0x5F},
7108c2ecf20Sopenharmony_ci	{CDC_A_SLOPE_COMP_IP_ZERO, 0x88},
7118c2ecf20Sopenharmony_ci	{CDC_A_SEC_ACCESS, 0xA5},
7128c2ecf20Sopenharmony_ci	{CDC_A_PERPH_RESET_CTL3, 0x0F},
7138c2ecf20Sopenharmony_ci	{CDC_A_CURRENT_LIMIT, 0x82},
7148c2ecf20Sopenharmony_ci	{CDC_A_SPKR_DAC_CTL, 0x03},
7158c2ecf20Sopenharmony_ci	{CDC_A_SPKR_OCP_CTL, 0xE1},
7168c2ecf20Sopenharmony_ci	{CDC_A_MASTER_BIAS_CTL, 0x30},
7178c2ecf20Sopenharmony_ci};
7188c2ecf20Sopenharmony_ci
7198c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_probe(struct snd_soc_component *component)
7208c2ecf20Sopenharmony_ci{
7218c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *priv = dev_get_drvdata(component->dev);
7228c2ecf20Sopenharmony_ci	int err, reg;
7238c2ecf20Sopenharmony_ci
7248c2ecf20Sopenharmony_ci	err = regulator_bulk_enable(ARRAY_SIZE(priv->supplies), priv->supplies);
7258c2ecf20Sopenharmony_ci	if (err != 0) {
7268c2ecf20Sopenharmony_ci		dev_err(component->dev, "failed to enable regulators (%d)\n", err);
7278c2ecf20Sopenharmony_ci		return err;
7288c2ecf20Sopenharmony_ci	}
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci	snd_soc_component_init_regmap(component,
7318c2ecf20Sopenharmony_ci				  dev_get_regmap(component->dev->parent, NULL));
7328c2ecf20Sopenharmony_ci	snd_soc_component_set_drvdata(component, priv);
7338c2ecf20Sopenharmony_ci	priv->pmic_rev = snd_soc_component_read(component, CDC_D_REVISION1);
7348c2ecf20Sopenharmony_ci	priv->codec_version = snd_soc_component_read(component, CDC_D_PERPH_SUBTYPE);
7358c2ecf20Sopenharmony_ci
7368c2ecf20Sopenharmony_ci	dev_info(component->dev, "PMIC REV: %d\t CODEC Version: %d\n",
7378c2ecf20Sopenharmony_ci		 priv->pmic_rev, priv->codec_version);
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_ci	snd_soc_component_write(component, CDC_D_PERPH_RESET_CTL4, 0x01);
7408c2ecf20Sopenharmony_ci	snd_soc_component_write(component, CDC_A_PERPH_RESET_CTL4, 0x01);
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_ci	for (reg = 0; reg < ARRAY_SIZE(wcd_reg_defaults_2_0); reg++)
7438c2ecf20Sopenharmony_ci		snd_soc_component_write(component, wcd_reg_defaults_2_0[reg].reg,
7448c2ecf20Sopenharmony_ci			      wcd_reg_defaults_2_0[reg].def);
7458c2ecf20Sopenharmony_ci
7468c2ecf20Sopenharmony_ci	priv->component = component;
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, CDC_D_CDC_RST_CTL,
7498c2ecf20Sopenharmony_ci			    RST_CTL_DIG_SW_RST_N_MASK,
7508c2ecf20Sopenharmony_ci			    RST_CTL_DIG_SW_RST_N_REMOVE_RESET);
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_ci	pm8916_wcd_setup_mbhc(priv);
7538c2ecf20Sopenharmony_ci
7548c2ecf20Sopenharmony_ci	return 0;
7558c2ecf20Sopenharmony_ci}
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_cistatic void pm8916_wcd_analog_remove(struct snd_soc_component *component)
7588c2ecf20Sopenharmony_ci{
7598c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *priv = dev_get_drvdata(component->dev);
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, CDC_D_CDC_RST_CTL,
7628c2ecf20Sopenharmony_ci			    RST_CTL_DIG_SW_RST_N_MASK, 0);
7638c2ecf20Sopenharmony_ci
7648c2ecf20Sopenharmony_ci	regulator_bulk_disable(ARRAY_SIZE(priv->supplies),
7658c2ecf20Sopenharmony_ci				      priv->supplies);
7668c2ecf20Sopenharmony_ci}
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route pm8916_wcd_analog_audio_map[] = {
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci	{"PDM_RX1", NULL, "PDM Playback"},
7718c2ecf20Sopenharmony_ci	{"PDM_RX2", NULL, "PDM Playback"},
7728c2ecf20Sopenharmony_ci	{"PDM_RX3", NULL, "PDM Playback"},
7738c2ecf20Sopenharmony_ci	{"PDM Capture", NULL, "PDM_TX"},
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_ci	/* ADC Connections */
7768c2ecf20Sopenharmony_ci	{"PDM_TX", NULL, "ADC2"},
7778c2ecf20Sopenharmony_ci	{"PDM_TX", NULL, "ADC3"},
7788c2ecf20Sopenharmony_ci	{"ADC2", NULL, "ADC2 MUX"},
7798c2ecf20Sopenharmony_ci	{"ADC3", NULL, "ADC2 MUX"},
7808c2ecf20Sopenharmony_ci	{"ADC2 MUX", "INP2", "ADC2_INP2"},
7818c2ecf20Sopenharmony_ci	{"ADC2 MUX", "INP3", "ADC2_INP3"},
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci	{"PDM_TX", NULL, "ADC1"},
7848c2ecf20Sopenharmony_ci	{"ADC1", NULL, "AMIC1"},
7858c2ecf20Sopenharmony_ci	{"ADC2_INP2", NULL, "AMIC2"},
7868c2ecf20Sopenharmony_ci	{"ADC2_INP3", NULL, "AMIC3"},
7878c2ecf20Sopenharmony_ci
7888c2ecf20Sopenharmony_ci	/* RDAC Connections */
7898c2ecf20Sopenharmony_ci	{"HPHR DAC", NULL, "RDAC2 MUX"},
7908c2ecf20Sopenharmony_ci	{"RDAC2 MUX", "RX1", "PDM_RX1"},
7918c2ecf20Sopenharmony_ci	{"RDAC2 MUX", "RX2", "PDM_RX2"},
7928c2ecf20Sopenharmony_ci	{"HPHL DAC", NULL, "PDM_RX1"},
7938c2ecf20Sopenharmony_ci	{"PDM_RX1", NULL, "RXD1_CLK"},
7948c2ecf20Sopenharmony_ci	{"PDM_RX2", NULL, "RXD2_CLK"},
7958c2ecf20Sopenharmony_ci	{"PDM_RX3", NULL, "RXD3_CLK"},
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci	{"PDM_RX1", NULL, "RXD_PDM_CLK"},
7988c2ecf20Sopenharmony_ci	{"PDM_RX2", NULL, "RXD_PDM_CLK"},
7998c2ecf20Sopenharmony_ci	{"PDM_RX3", NULL, "RXD_PDM_CLK"},
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_ci	{"ADC1", NULL, "TXD_CLK"},
8028c2ecf20Sopenharmony_ci	{"ADC2", NULL, "TXD_CLK"},
8038c2ecf20Sopenharmony_ci	{"ADC3", NULL, "TXD_CLK"},
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	{"ADC1", NULL, "TXA_CLK25"},
8068c2ecf20Sopenharmony_ci	{"ADC2", NULL, "TXA_CLK25"},
8078c2ecf20Sopenharmony_ci	{"ADC3", NULL, "TXA_CLK25"},
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci	{"PDM_RX1", NULL, "A_MCLK2"},
8108c2ecf20Sopenharmony_ci	{"PDM_RX2", NULL, "A_MCLK2"},
8118c2ecf20Sopenharmony_ci	{"PDM_RX3", NULL, "A_MCLK2"},
8128c2ecf20Sopenharmony_ci
8138c2ecf20Sopenharmony_ci	{"PDM_TX", NULL, "A_MCLK2"},
8148c2ecf20Sopenharmony_ci	{"A_MCLK2", NULL, "A_MCLK"},
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	/* Earpiece (RX MIX1) */
8178c2ecf20Sopenharmony_ci	{"EAR", NULL, "EAR_S"},
8188c2ecf20Sopenharmony_ci	{"EAR_S", "Switch", "EAR PA"},
8198c2ecf20Sopenharmony_ci	{"EAR PA", NULL, "RX_BIAS"},
8208c2ecf20Sopenharmony_ci	{"EAR PA", NULL, "HPHL DAC"},
8218c2ecf20Sopenharmony_ci	{"EAR PA", NULL, "HPHR DAC"},
8228c2ecf20Sopenharmony_ci	{"EAR PA", NULL, "EAR CP"},
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_ci	/* Headset (RX MIX1 and RX MIX2) */
8258c2ecf20Sopenharmony_ci	{"HEADPHONE", NULL, "HPHL PA"},
8268c2ecf20Sopenharmony_ci	{"HEADPHONE", NULL, "HPHR PA"},
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci	{"HPHL DAC", NULL, "EAR_HPHL_CLK"},
8298c2ecf20Sopenharmony_ci	{"HPHR DAC", NULL, "EAR_HPHR_CLK"},
8308c2ecf20Sopenharmony_ci
8318c2ecf20Sopenharmony_ci	{"CP", NULL, "NCP_CLK"},
8328c2ecf20Sopenharmony_ci
8338c2ecf20Sopenharmony_ci	{"HPHL PA", NULL, "HPHL"},
8348c2ecf20Sopenharmony_ci	{"HPHR PA", NULL, "HPHR"},
8358c2ecf20Sopenharmony_ci	{"HPHL PA", NULL, "CP"},
8368c2ecf20Sopenharmony_ci	{"HPHL PA", NULL, "RX_BIAS"},
8378c2ecf20Sopenharmony_ci	{"HPHR PA", NULL, "CP"},
8388c2ecf20Sopenharmony_ci	{"HPHR PA", NULL, "RX_BIAS"},
8398c2ecf20Sopenharmony_ci	{"HPHL", "Switch", "HPHL DAC"},
8408c2ecf20Sopenharmony_ci	{"HPHR", "Switch", "HPHR DAC"},
8418c2ecf20Sopenharmony_ci
8428c2ecf20Sopenharmony_ci	{"RX_BIAS", NULL, "DAC_REF"},
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_ci	{"SPK_OUT", NULL, "SPK PA"},
8458c2ecf20Sopenharmony_ci	{"SPK PA", NULL, "RX_BIAS"},
8468c2ecf20Sopenharmony_ci	{"SPK PA", NULL, "SPKR_CLK"},
8478c2ecf20Sopenharmony_ci	{"SPK PA", NULL, "SPK DAC"},
8488c2ecf20Sopenharmony_ci	{"SPK DAC", "Switch", "PDM_RX3"},
8498c2ecf20Sopenharmony_ci
8508c2ecf20Sopenharmony_ci	{"MIC_BIAS1", NULL, "INT_LDO_H"},
8518c2ecf20Sopenharmony_ci	{"MIC_BIAS2", NULL, "INT_LDO_H"},
8528c2ecf20Sopenharmony_ci	{"MIC_BIAS1", NULL, "vdd-micbias"},
8538c2ecf20Sopenharmony_ci	{"MIC_BIAS2", NULL, "vdd-micbias"},
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci	{"MIC BIAS External1", NULL, "MIC_BIAS1"},
8568c2ecf20Sopenharmony_ci	{"MIC BIAS Internal1", NULL, "MIC_BIAS1"},
8578c2ecf20Sopenharmony_ci	{"MIC BIAS External2", NULL, "MIC_BIAS2"},
8588c2ecf20Sopenharmony_ci	{"MIC BIAS Internal2", NULL, "MIC_BIAS2"},
8598c2ecf20Sopenharmony_ci	{"MIC BIAS Internal3", NULL, "MIC_BIAS1"},
8608c2ecf20Sopenharmony_ci};
8618c2ecf20Sopenharmony_ci
8628c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget pm8916_wcd_analog_dapm_widgets[] = {
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_ci	SND_SOC_DAPM_AIF_IN("PDM_RX1", NULL, 0, SND_SOC_NOPM, 0, 0),
8658c2ecf20Sopenharmony_ci	SND_SOC_DAPM_AIF_IN("PDM_RX2", NULL, 0, SND_SOC_NOPM, 0, 0),
8668c2ecf20Sopenharmony_ci	SND_SOC_DAPM_AIF_IN("PDM_RX3", NULL, 0, SND_SOC_NOPM, 0, 0),
8678c2ecf20Sopenharmony_ci	SND_SOC_DAPM_AIF_OUT("PDM_TX", NULL, 0, SND_SOC_NOPM, 0, 0),
8688c2ecf20Sopenharmony_ci
8698c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AMIC1"),
8708c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AMIC3"),
8718c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("AMIC2"),
8728c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("EAR"),
8738c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("HEADPHONE"),
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_ci	/* RX stuff */
8768c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("INT_LDO_H", SND_SOC_NOPM, 1, 0, NULL, 0),
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA_E("EAR PA", SND_SOC_NOPM,
8798c2ecf20Sopenharmony_ci			   0, 0, NULL, 0,
8808c2ecf20Sopenharmony_ci			   pm8916_wcd_analog_enable_ear_pa,
8818c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
8828c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
8838c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("EAR_S", SND_SOC_NOPM, 0, 0, &ear_mux),
8848c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("EAR CP", CDC_A_NCP_EN, 4, 0, NULL, 0),
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("HPHL PA", CDC_A_RX_HPH_CNP_EN, 5, 0, NULL, 0),
8878c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("HPHL", SND_SOC_NOPM, 0, 0, &hphl_mux),
8888c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("HPHL DAC", CDC_A_RX_HPH_L_PA_DAC_CTL, 3, 0, NULL,
8898c2ecf20Sopenharmony_ci			   0),
8908c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA("HPHR PA", CDC_A_RX_HPH_CNP_EN, 4, 0, NULL, 0),
8918c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("HPHR", SND_SOC_NOPM, 0, 0, &hphr_mux),
8928c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("HPHR DAC", CDC_A_RX_HPH_R_PA_DAC_CTL, 3, 0, NULL,
8938c2ecf20Sopenharmony_ci			   0),
8948c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("SPK DAC", SND_SOC_NOPM, 0, 0,
8958c2ecf20Sopenharmony_ci			   spkr_switch, ARRAY_SIZE(spkr_switch)),
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci	/* Speaker */
8988c2ecf20Sopenharmony_ci	SND_SOC_DAPM_OUTPUT("SPK_OUT"),
8998c2ecf20Sopenharmony_ci	SND_SOC_DAPM_PGA_E("SPK PA", CDC_A_SPKR_DRV_CTL,
9008c2ecf20Sopenharmony_ci			   6, 0, NULL, 0,
9018c2ecf20Sopenharmony_ci			   pm8916_wcd_analog_enable_spk_pa,
9028c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
9038c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD),
9048c2ecf20Sopenharmony_ci	SND_SOC_DAPM_REGULATOR_SUPPLY("vdd-micbias", 0, 0),
9058c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("CP", CDC_A_NCP_EN, 0, 0, NULL, 0),
9068c2ecf20Sopenharmony_ci
9078c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("DAC_REF", CDC_A_RX_COM_BIAS_DAC, 0, 0, NULL, 0),
9088c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("RX_BIAS", CDC_A_RX_COM_BIAS_DAC, 7, 0, NULL, 0),
9098c2ecf20Sopenharmony_ci
9108c2ecf20Sopenharmony_ci	/* TX */
9118c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC_BIAS1", CDC_A_MICB_1_EN, 7, 0,
9128c2ecf20Sopenharmony_ci			    pm8916_wcd_analog_enable_micbias1,
9138c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_POST_PMU),
9148c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC_BIAS2", CDC_A_MICB_2_EN, 7, 0,
9158c2ecf20Sopenharmony_ci			    pm8916_wcd_analog_enable_micbias2,
9168c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_POST_PMU),
9178c2ecf20Sopenharmony_ci
9188c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC BIAS External1", SND_SOC_NOPM, 0, 0, NULL, 0),
9198c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC BIAS External2", SND_SOC_NOPM, 0, 0, NULL, 0),
9208c2ecf20Sopenharmony_ci
9218c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC BIAS Internal1", CDC_A_MICB_1_INT_RBIAS, 7, 0,
9228c2ecf20Sopenharmony_ci			    pm8916_wcd_analog_enable_micbias_int,
9238c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_PRE_PMU),
9248c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC BIAS Internal2", CDC_A_MICB_1_INT_RBIAS, 4, 0,
9258c2ecf20Sopenharmony_ci			    pm8916_wcd_analog_enable_micbias_int2,
9268c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
9278c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_POST_PMD),
9288c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC BIAS Internal3", CDC_A_MICB_1_INT_RBIAS, 1, 0,
9298c2ecf20Sopenharmony_ci			    pm8916_wcd_analog_enable_micbias_int,
9308c2ecf20Sopenharmony_ci			    SND_SOC_DAPM_PRE_PMU),
9318c2ecf20Sopenharmony_ci
9328c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC_E("ADC1", NULL, CDC_A_TX_1_EN, 7, 0,
9338c2ecf20Sopenharmony_ci			   pm8916_wcd_analog_enable_adc,
9348c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
9358c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_POST_PMD),
9368c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC_E("ADC2_INP2", NULL, CDC_A_TX_2_EN, 7, 0,
9378c2ecf20Sopenharmony_ci			   pm8916_wcd_analog_enable_adc,
9388c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
9398c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_POST_PMD),
9408c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC_E("ADC2_INP3", NULL, CDC_A_TX_3_EN, 7, 0,
9418c2ecf20Sopenharmony_ci			   pm8916_wcd_analog_enable_adc,
9428c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU |
9438c2ecf20Sopenharmony_ci			   SND_SOC_DAPM_POST_PMD),
9448c2ecf20Sopenharmony_ci
9458c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("ADC2", SND_SOC_NOPM, 0, 0, NULL, 0),
9468c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MIXER("ADC3", SND_SOC_NOPM, 0, 0, NULL, 0),
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("ADC2 MUX", SND_SOC_NOPM, 0, 0, &tx_adc2_mux),
9498c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("RDAC2 MUX", SND_SOC_NOPM, 0, 0, &rdac2_mux),
9508c2ecf20Sopenharmony_ci
9518c2ecf20Sopenharmony_ci	/* Analog path clocks */
9528c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("EAR_HPHR_CLK", CDC_D_CDC_ANA_CLK_CTL, 0, 0, NULL,
9538c2ecf20Sopenharmony_ci			    0),
9548c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("EAR_HPHL_CLK", CDC_D_CDC_ANA_CLK_CTL, 1, 0, NULL,
9558c2ecf20Sopenharmony_ci			    0),
9568c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("SPKR_CLK", CDC_D_CDC_ANA_CLK_CTL, 4, 0, NULL, 0),
9578c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("TXA_CLK25", CDC_D_CDC_ANA_CLK_CTL, 5, 0, NULL, 0),
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_ci	/* Digital path clocks */
9608c2ecf20Sopenharmony_ci
9618c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("RXD1_CLK", CDC_D_CDC_DIG_CLK_CTL, 0, 0, NULL, 0),
9628c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("RXD2_CLK", CDC_D_CDC_DIG_CLK_CTL, 1, 0, NULL, 0),
9638c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("RXD3_CLK", CDC_D_CDC_DIG_CLK_CTL, 2, 0, NULL, 0),
9648c2ecf20Sopenharmony_ci
9658c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("TXD_CLK", CDC_D_CDC_DIG_CLK_CTL, 4, 0, NULL, 0),
9668c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("NCP_CLK", CDC_D_CDC_DIG_CLK_CTL, 6, 0, NULL, 0),
9678c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("RXD_PDM_CLK", CDC_D_CDC_DIG_CLK_CTL, 7, 0, NULL,
9688c2ecf20Sopenharmony_ci			    0),
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_ci	/* System Clock source */
9718c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("A_MCLK", CDC_D_CDC_TOP_CLK_CTL, 2, 0, NULL, 0),
9728c2ecf20Sopenharmony_ci	/* TX ADC and RX DAC Clock source. */
9738c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("A_MCLK2", CDC_D_CDC_TOP_CLK_CTL, 3, 0, NULL, 0),
9748c2ecf20Sopenharmony_ci};
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_set_jack(struct snd_soc_component *component,
9778c2ecf20Sopenharmony_ci				      struct snd_soc_jack *jack,
9788c2ecf20Sopenharmony_ci				      void *data)
9798c2ecf20Sopenharmony_ci{
9808c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *wcd = snd_soc_component_get_drvdata(component);
9818c2ecf20Sopenharmony_ci
9828c2ecf20Sopenharmony_ci	wcd->jack = jack;
9838c2ecf20Sopenharmony_ci
9848c2ecf20Sopenharmony_ci	return 0;
9858c2ecf20Sopenharmony_ci}
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_cistatic irqreturn_t mbhc_btn_release_irq_handler(int irq, void *arg)
9888c2ecf20Sopenharmony_ci{
9898c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *priv = arg;
9908c2ecf20Sopenharmony_ci
9918c2ecf20Sopenharmony_ci	if (priv->detect_accessory_type) {
9928c2ecf20Sopenharmony_ci		struct snd_soc_component *component = priv->component;
9938c2ecf20Sopenharmony_ci		u32 val = snd_soc_component_read(component, CDC_A_MBHC_RESULT_1);
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_ci		/* check if its BTN0 thats released */
9968c2ecf20Sopenharmony_ci		if ((val != -1) && !(val & CDC_A_MBHC_RESULT_1_BTN_RESULT_MASK))
9978c2ecf20Sopenharmony_ci			priv->mbhc_btn0_released = true;
9988c2ecf20Sopenharmony_ci
9998c2ecf20Sopenharmony_ci	} else {
10008c2ecf20Sopenharmony_ci		snd_soc_jack_report(priv->jack, 0, btn_mask);
10018c2ecf20Sopenharmony_ci	}
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
10048c2ecf20Sopenharmony_ci}
10058c2ecf20Sopenharmony_ci
10068c2ecf20Sopenharmony_cistatic irqreturn_t mbhc_btn_press_irq_handler(int irq, void *arg)
10078c2ecf20Sopenharmony_ci{
10088c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *priv = arg;
10098c2ecf20Sopenharmony_ci	struct snd_soc_component *component = priv->component;
10108c2ecf20Sopenharmony_ci	u32 btn_result;
10118c2ecf20Sopenharmony_ci
10128c2ecf20Sopenharmony_ci	btn_result = snd_soc_component_read(component, CDC_A_MBHC_RESULT_1) &
10138c2ecf20Sopenharmony_ci				  CDC_A_MBHC_RESULT_1_BTN_RESULT_MASK;
10148c2ecf20Sopenharmony_ci
10158c2ecf20Sopenharmony_ci	switch (btn_result) {
10168c2ecf20Sopenharmony_ci	case 0xf:
10178c2ecf20Sopenharmony_ci		snd_soc_jack_report(priv->jack, SND_JACK_BTN_4, btn_mask);
10188c2ecf20Sopenharmony_ci		break;
10198c2ecf20Sopenharmony_ci	case 0x7:
10208c2ecf20Sopenharmony_ci		snd_soc_jack_report(priv->jack, SND_JACK_BTN_3, btn_mask);
10218c2ecf20Sopenharmony_ci		break;
10228c2ecf20Sopenharmony_ci	case 0x3:
10238c2ecf20Sopenharmony_ci		snd_soc_jack_report(priv->jack, SND_JACK_BTN_2, btn_mask);
10248c2ecf20Sopenharmony_ci		break;
10258c2ecf20Sopenharmony_ci	case 0x1:
10268c2ecf20Sopenharmony_ci		snd_soc_jack_report(priv->jack, SND_JACK_BTN_1, btn_mask);
10278c2ecf20Sopenharmony_ci		break;
10288c2ecf20Sopenharmony_ci	case 0x0:
10298c2ecf20Sopenharmony_ci		/* handle BTN_0 specially for type detection */
10308c2ecf20Sopenharmony_ci		if (!priv->detect_accessory_type)
10318c2ecf20Sopenharmony_ci			snd_soc_jack_report(priv->jack,
10328c2ecf20Sopenharmony_ci					    SND_JACK_BTN_0, btn_mask);
10338c2ecf20Sopenharmony_ci		break;
10348c2ecf20Sopenharmony_ci	default:
10358c2ecf20Sopenharmony_ci		dev_err(component->dev,
10368c2ecf20Sopenharmony_ci			"Unexpected button press result (%x)", btn_result);
10378c2ecf20Sopenharmony_ci		break;
10388c2ecf20Sopenharmony_ci	}
10398c2ecf20Sopenharmony_ci
10408c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
10418c2ecf20Sopenharmony_ci}
10428c2ecf20Sopenharmony_ci
10438c2ecf20Sopenharmony_cistatic irqreturn_t pm8916_mbhc_switch_irq_handler(int irq, void *arg)
10448c2ecf20Sopenharmony_ci{
10458c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *priv = arg;
10468c2ecf20Sopenharmony_ci	struct snd_soc_component *component = priv->component;
10478c2ecf20Sopenharmony_ci	bool ins = false;
10488c2ecf20Sopenharmony_ci
10498c2ecf20Sopenharmony_ci	if (snd_soc_component_read(component, CDC_A_MBHC_DET_CTL_1) &
10508c2ecf20Sopenharmony_ci				CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK)
10518c2ecf20Sopenharmony_ci		ins = true;
10528c2ecf20Sopenharmony_ci
10538c2ecf20Sopenharmony_ci	/* Set the detection type appropriately */
10548c2ecf20Sopenharmony_ci	snd_soc_component_update_bits(component, CDC_A_MBHC_DET_CTL_1,
10558c2ecf20Sopenharmony_ci			    CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_MASK,
10568c2ecf20Sopenharmony_ci			    (!ins << CDC_A_MBHC_DET_CTL_MECH_DET_TYPE_SHIFT));
10578c2ecf20Sopenharmony_ci
10588c2ecf20Sopenharmony_ci
10598c2ecf20Sopenharmony_ci	if (ins) { /* hs insertion */
10608c2ecf20Sopenharmony_ci		bool micbias_enabled = false;
10618c2ecf20Sopenharmony_ci
10628c2ecf20Sopenharmony_ci		if (snd_soc_component_read(component, CDC_A_MICB_2_EN) &
10638c2ecf20Sopenharmony_ci				CDC_A_MICB_2_EN_ENABLE)
10648c2ecf20Sopenharmony_ci			micbias_enabled = true;
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_ci		pm8916_mbhc_configure_bias(priv, micbias_enabled);
10678c2ecf20Sopenharmony_ci
10688c2ecf20Sopenharmony_ci		/*
10698c2ecf20Sopenharmony_ci		 * if only a btn0 press event is receive just before
10708c2ecf20Sopenharmony_ci		 * insert event then its a 3 pole headphone else if
10718c2ecf20Sopenharmony_ci		 * both press and release event received then its
10728c2ecf20Sopenharmony_ci		 * a headset.
10738c2ecf20Sopenharmony_ci		 */
10748c2ecf20Sopenharmony_ci		if (priv->mbhc_btn0_released)
10758c2ecf20Sopenharmony_ci			snd_soc_jack_report(priv->jack,
10768c2ecf20Sopenharmony_ci					    SND_JACK_HEADSET, hs_jack_mask);
10778c2ecf20Sopenharmony_ci		else
10788c2ecf20Sopenharmony_ci			snd_soc_jack_report(priv->jack,
10798c2ecf20Sopenharmony_ci					    SND_JACK_HEADPHONE, hs_jack_mask);
10808c2ecf20Sopenharmony_ci
10818c2ecf20Sopenharmony_ci		priv->detect_accessory_type = false;
10828c2ecf20Sopenharmony_ci
10838c2ecf20Sopenharmony_ci	} else { /* removal */
10848c2ecf20Sopenharmony_ci		snd_soc_jack_report(priv->jack, 0, hs_jack_mask);
10858c2ecf20Sopenharmony_ci		priv->detect_accessory_type = true;
10868c2ecf20Sopenharmony_ci		priv->mbhc_btn0_released = false;
10878c2ecf20Sopenharmony_ci	}
10888c2ecf20Sopenharmony_ci
10898c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
10908c2ecf20Sopenharmony_ci}
10918c2ecf20Sopenharmony_ci
10928c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver pm8916_wcd_analog_dai[] = {
10938c2ecf20Sopenharmony_ci	[0] = {
10948c2ecf20Sopenharmony_ci	       .name = "pm8916_wcd_analog_pdm_rx",
10958c2ecf20Sopenharmony_ci	       .id = 0,
10968c2ecf20Sopenharmony_ci	       .playback = {
10978c2ecf20Sopenharmony_ci			    .stream_name = "PDM Playback",
10988c2ecf20Sopenharmony_ci			    .rates = MSM8916_WCD_ANALOG_RATES,
10998c2ecf20Sopenharmony_ci			    .formats = MSM8916_WCD_ANALOG_FORMATS,
11008c2ecf20Sopenharmony_ci			    .channels_min = 1,
11018c2ecf20Sopenharmony_ci			    .channels_max = 3,
11028c2ecf20Sopenharmony_ci			    },
11038c2ecf20Sopenharmony_ci	       },
11048c2ecf20Sopenharmony_ci	[1] = {
11058c2ecf20Sopenharmony_ci	       .name = "pm8916_wcd_analog_pdm_tx",
11068c2ecf20Sopenharmony_ci	       .id = 1,
11078c2ecf20Sopenharmony_ci	       .capture = {
11088c2ecf20Sopenharmony_ci			   .stream_name = "PDM Capture",
11098c2ecf20Sopenharmony_ci			   .rates = MSM8916_WCD_ANALOG_RATES,
11108c2ecf20Sopenharmony_ci			   .formats = MSM8916_WCD_ANALOG_FORMATS,
11118c2ecf20Sopenharmony_ci			   .channels_min = 1,
11128c2ecf20Sopenharmony_ci			   .channels_max = 4,
11138c2ecf20Sopenharmony_ci			   },
11148c2ecf20Sopenharmony_ci	       },
11158c2ecf20Sopenharmony_ci};
11168c2ecf20Sopenharmony_ci
11178c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver pm8916_wcd_analog = {
11188c2ecf20Sopenharmony_ci	.probe			= pm8916_wcd_analog_probe,
11198c2ecf20Sopenharmony_ci	.remove			= pm8916_wcd_analog_remove,
11208c2ecf20Sopenharmony_ci	.set_jack		= pm8916_wcd_analog_set_jack,
11218c2ecf20Sopenharmony_ci	.controls		= pm8916_wcd_analog_snd_controls,
11228c2ecf20Sopenharmony_ci	.num_controls		= ARRAY_SIZE(pm8916_wcd_analog_snd_controls),
11238c2ecf20Sopenharmony_ci	.dapm_widgets		= pm8916_wcd_analog_dapm_widgets,
11248c2ecf20Sopenharmony_ci	.num_dapm_widgets	= ARRAY_SIZE(pm8916_wcd_analog_dapm_widgets),
11258c2ecf20Sopenharmony_ci	.dapm_routes		= pm8916_wcd_analog_audio_map,
11268c2ecf20Sopenharmony_ci	.num_dapm_routes	= ARRAY_SIZE(pm8916_wcd_analog_audio_map),
11278c2ecf20Sopenharmony_ci	.idle_bias_on		= 1,
11288c2ecf20Sopenharmony_ci	.use_pmdown_time	= 1,
11298c2ecf20Sopenharmony_ci	.endianness		= 1,
11308c2ecf20Sopenharmony_ci	.non_legacy_dai_naming	= 1,
11318c2ecf20Sopenharmony_ci};
11328c2ecf20Sopenharmony_ci
11338c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_parse_dt(struct device *dev,
11348c2ecf20Sopenharmony_ci				       struct pm8916_wcd_analog_priv *priv)
11358c2ecf20Sopenharmony_ci{
11368c2ecf20Sopenharmony_ci	int rval;
11378c2ecf20Sopenharmony_ci
11388c2ecf20Sopenharmony_ci	if (of_property_read_bool(dev->of_node, "qcom,micbias1-ext-cap"))
11398c2ecf20Sopenharmony_ci		priv->micbias1_cap_mode = MICB_1_EN_EXT_BYP_CAP;
11408c2ecf20Sopenharmony_ci	else
11418c2ecf20Sopenharmony_ci		priv->micbias1_cap_mode = MICB_1_EN_NO_EXT_BYP_CAP;
11428c2ecf20Sopenharmony_ci
11438c2ecf20Sopenharmony_ci	if (of_property_read_bool(dev->of_node, "qcom,micbias2-ext-cap"))
11448c2ecf20Sopenharmony_ci		priv->micbias2_cap_mode = MICB_1_EN_EXT_BYP_CAP;
11458c2ecf20Sopenharmony_ci	else
11468c2ecf20Sopenharmony_ci		priv->micbias2_cap_mode = MICB_1_EN_NO_EXT_BYP_CAP;
11478c2ecf20Sopenharmony_ci
11488c2ecf20Sopenharmony_ci	of_property_read_u32(dev->of_node, "qcom,micbias-lvl",
11498c2ecf20Sopenharmony_ci			     &priv->micbias_mv);
11508c2ecf20Sopenharmony_ci
11518c2ecf20Sopenharmony_ci	if (of_property_read_bool(dev->of_node,
11528c2ecf20Sopenharmony_ci				  "qcom,hphl-jack-type-normally-open"))
11538c2ecf20Sopenharmony_ci		priv->hphl_jack_type_normally_open = true;
11548c2ecf20Sopenharmony_ci	else
11558c2ecf20Sopenharmony_ci		priv->hphl_jack_type_normally_open = false;
11568c2ecf20Sopenharmony_ci
11578c2ecf20Sopenharmony_ci	if (of_property_read_bool(dev->of_node,
11588c2ecf20Sopenharmony_ci				  "qcom,gnd-jack-type-normally-open"))
11598c2ecf20Sopenharmony_ci		priv->gnd_jack_type_normally_open = true;
11608c2ecf20Sopenharmony_ci	else
11618c2ecf20Sopenharmony_ci		priv->gnd_jack_type_normally_open = false;
11628c2ecf20Sopenharmony_ci
11638c2ecf20Sopenharmony_ci	priv->mbhc_btn_enabled = true;
11648c2ecf20Sopenharmony_ci	rval = of_property_read_u32_array(dev->of_node,
11658c2ecf20Sopenharmony_ci					  "qcom,mbhc-vthreshold-low",
11668c2ecf20Sopenharmony_ci					  &priv->vref_btn_cs[0],
11678c2ecf20Sopenharmony_ci					  MBHC_MAX_BUTTONS);
11688c2ecf20Sopenharmony_ci	if (rval < 0) {
11698c2ecf20Sopenharmony_ci		priv->mbhc_btn_enabled = false;
11708c2ecf20Sopenharmony_ci	} else {
11718c2ecf20Sopenharmony_ci		rval = of_property_read_u32_array(dev->of_node,
11728c2ecf20Sopenharmony_ci						  "qcom,mbhc-vthreshold-high",
11738c2ecf20Sopenharmony_ci						  &priv->vref_btn_micb[0],
11748c2ecf20Sopenharmony_ci						  MBHC_MAX_BUTTONS);
11758c2ecf20Sopenharmony_ci		if (rval < 0)
11768c2ecf20Sopenharmony_ci			priv->mbhc_btn_enabled = false;
11778c2ecf20Sopenharmony_ci	}
11788c2ecf20Sopenharmony_ci
11798c2ecf20Sopenharmony_ci	if (!priv->mbhc_btn_enabled)
11808c2ecf20Sopenharmony_ci		dev_err(dev,
11818c2ecf20Sopenharmony_ci			"DT property missing, MBHC btn detection disabled\n");
11828c2ecf20Sopenharmony_ci
11838c2ecf20Sopenharmony_ci
11848c2ecf20Sopenharmony_ci	return 0;
11858c2ecf20Sopenharmony_ci}
11868c2ecf20Sopenharmony_ci
11878c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_spmi_probe(struct platform_device *pdev)
11888c2ecf20Sopenharmony_ci{
11898c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *priv;
11908c2ecf20Sopenharmony_ci	struct device *dev = &pdev->dev;
11918c2ecf20Sopenharmony_ci	int ret, i, irq;
11928c2ecf20Sopenharmony_ci
11938c2ecf20Sopenharmony_ci	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
11948c2ecf20Sopenharmony_ci	if (!priv)
11958c2ecf20Sopenharmony_ci		return -ENOMEM;
11968c2ecf20Sopenharmony_ci
11978c2ecf20Sopenharmony_ci	ret = pm8916_wcd_analog_parse_dt(dev, priv);
11988c2ecf20Sopenharmony_ci	if (ret < 0)
11998c2ecf20Sopenharmony_ci		return ret;
12008c2ecf20Sopenharmony_ci
12018c2ecf20Sopenharmony_ci	priv->mclk = devm_clk_get(dev, "mclk");
12028c2ecf20Sopenharmony_ci	if (IS_ERR(priv->mclk)) {
12038c2ecf20Sopenharmony_ci		dev_err(dev, "failed to get mclk\n");
12048c2ecf20Sopenharmony_ci		return PTR_ERR(priv->mclk);
12058c2ecf20Sopenharmony_ci	}
12068c2ecf20Sopenharmony_ci
12078c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(supply_names); i++)
12088c2ecf20Sopenharmony_ci		priv->supplies[i].supply = supply_names[i];
12098c2ecf20Sopenharmony_ci
12108c2ecf20Sopenharmony_ci	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(priv->supplies),
12118c2ecf20Sopenharmony_ci				    priv->supplies);
12128c2ecf20Sopenharmony_ci	if (ret) {
12138c2ecf20Sopenharmony_ci		dev_err(dev, "Failed to get regulator supplies %d\n", ret);
12148c2ecf20Sopenharmony_ci		return ret;
12158c2ecf20Sopenharmony_ci	}
12168c2ecf20Sopenharmony_ci
12178c2ecf20Sopenharmony_ci	ret = clk_prepare_enable(priv->mclk);
12188c2ecf20Sopenharmony_ci	if (ret < 0) {
12198c2ecf20Sopenharmony_ci		dev_err(dev, "failed to enable mclk %d\n", ret);
12208c2ecf20Sopenharmony_ci		return ret;
12218c2ecf20Sopenharmony_ci	}
12228c2ecf20Sopenharmony_ci
12238c2ecf20Sopenharmony_ci	irq = platform_get_irq_byname(pdev, "mbhc_switch_int");
12248c2ecf20Sopenharmony_ci	if (irq < 0) {
12258c2ecf20Sopenharmony_ci		ret = irq;
12268c2ecf20Sopenharmony_ci		goto err_disable_clk;
12278c2ecf20Sopenharmony_ci	}
12288c2ecf20Sopenharmony_ci
12298c2ecf20Sopenharmony_ci	ret = devm_request_threaded_irq(dev, irq, NULL,
12308c2ecf20Sopenharmony_ci			       pm8916_mbhc_switch_irq_handler,
12318c2ecf20Sopenharmony_ci			       IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
12328c2ecf20Sopenharmony_ci			       IRQF_ONESHOT,
12338c2ecf20Sopenharmony_ci			       "mbhc switch irq", priv);
12348c2ecf20Sopenharmony_ci	if (ret)
12358c2ecf20Sopenharmony_ci		dev_err(dev, "cannot request mbhc switch irq\n");
12368c2ecf20Sopenharmony_ci
12378c2ecf20Sopenharmony_ci	if (priv->mbhc_btn_enabled) {
12388c2ecf20Sopenharmony_ci		irq = platform_get_irq_byname(pdev, "mbhc_but_press_det");
12398c2ecf20Sopenharmony_ci		if (irq < 0) {
12408c2ecf20Sopenharmony_ci			ret = irq;
12418c2ecf20Sopenharmony_ci			goto err_disable_clk;
12428c2ecf20Sopenharmony_ci		}
12438c2ecf20Sopenharmony_ci
12448c2ecf20Sopenharmony_ci		ret = devm_request_threaded_irq(dev, irq, NULL,
12458c2ecf20Sopenharmony_ci				       mbhc_btn_press_irq_handler,
12468c2ecf20Sopenharmony_ci				       IRQF_TRIGGER_RISING |
12478c2ecf20Sopenharmony_ci				       IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
12488c2ecf20Sopenharmony_ci				       "mbhc btn press irq", priv);
12498c2ecf20Sopenharmony_ci		if (ret)
12508c2ecf20Sopenharmony_ci			dev_err(dev, "cannot request mbhc button press irq\n");
12518c2ecf20Sopenharmony_ci
12528c2ecf20Sopenharmony_ci		irq = platform_get_irq_byname(pdev, "mbhc_but_rel_det");
12538c2ecf20Sopenharmony_ci		if (irq < 0) {
12548c2ecf20Sopenharmony_ci			ret = irq;
12558c2ecf20Sopenharmony_ci			goto err_disable_clk;
12568c2ecf20Sopenharmony_ci		}
12578c2ecf20Sopenharmony_ci
12588c2ecf20Sopenharmony_ci		ret = devm_request_threaded_irq(dev, irq, NULL,
12598c2ecf20Sopenharmony_ci				       mbhc_btn_release_irq_handler,
12608c2ecf20Sopenharmony_ci				       IRQF_TRIGGER_RISING |
12618c2ecf20Sopenharmony_ci				       IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
12628c2ecf20Sopenharmony_ci				       "mbhc btn release irq", priv);
12638c2ecf20Sopenharmony_ci		if (ret)
12648c2ecf20Sopenharmony_ci			dev_err(dev, "cannot request mbhc button release irq\n");
12658c2ecf20Sopenharmony_ci
12668c2ecf20Sopenharmony_ci	}
12678c2ecf20Sopenharmony_ci
12688c2ecf20Sopenharmony_ci	dev_set_drvdata(dev, priv);
12698c2ecf20Sopenharmony_ci
12708c2ecf20Sopenharmony_ci	return devm_snd_soc_register_component(dev, &pm8916_wcd_analog,
12718c2ecf20Sopenharmony_ci				      pm8916_wcd_analog_dai,
12728c2ecf20Sopenharmony_ci				      ARRAY_SIZE(pm8916_wcd_analog_dai));
12738c2ecf20Sopenharmony_ci
12748c2ecf20Sopenharmony_cierr_disable_clk:
12758c2ecf20Sopenharmony_ci	clk_disable_unprepare(priv->mclk);
12768c2ecf20Sopenharmony_ci	return ret;
12778c2ecf20Sopenharmony_ci}
12788c2ecf20Sopenharmony_ci
12798c2ecf20Sopenharmony_cistatic int pm8916_wcd_analog_spmi_remove(struct platform_device *pdev)
12808c2ecf20Sopenharmony_ci{
12818c2ecf20Sopenharmony_ci	struct pm8916_wcd_analog_priv *priv = dev_get_drvdata(&pdev->dev);
12828c2ecf20Sopenharmony_ci
12838c2ecf20Sopenharmony_ci	clk_disable_unprepare(priv->mclk);
12848c2ecf20Sopenharmony_ci
12858c2ecf20Sopenharmony_ci	return 0;
12868c2ecf20Sopenharmony_ci}
12878c2ecf20Sopenharmony_ci
12888c2ecf20Sopenharmony_cistatic const struct of_device_id pm8916_wcd_analog_spmi_match_table[] = {
12898c2ecf20Sopenharmony_ci	{ .compatible = "qcom,pm8916-wcd-analog-codec", },
12908c2ecf20Sopenharmony_ci	{ }
12918c2ecf20Sopenharmony_ci};
12928c2ecf20Sopenharmony_ci
12938c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, pm8916_wcd_analog_spmi_match_table);
12948c2ecf20Sopenharmony_ci
12958c2ecf20Sopenharmony_cistatic struct platform_driver pm8916_wcd_analog_spmi_driver = {
12968c2ecf20Sopenharmony_ci	.driver = {
12978c2ecf20Sopenharmony_ci		   .name = "qcom,pm8916-wcd-spmi-codec",
12988c2ecf20Sopenharmony_ci		   .of_match_table = pm8916_wcd_analog_spmi_match_table,
12998c2ecf20Sopenharmony_ci	},
13008c2ecf20Sopenharmony_ci	.probe = pm8916_wcd_analog_spmi_probe,
13018c2ecf20Sopenharmony_ci	.remove = pm8916_wcd_analog_spmi_remove,
13028c2ecf20Sopenharmony_ci};
13038c2ecf20Sopenharmony_ci
13048c2ecf20Sopenharmony_cimodule_platform_driver(pm8916_wcd_analog_spmi_driver);
13058c2ecf20Sopenharmony_ci
13068c2ecf20Sopenharmony_ciMODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org>");
13078c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("PMIC PM8916 WCD Analog Codec driver");
13088c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
1309