18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * cs53l30.c  --  CS53l30 ALSA Soc Audio driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright 2015 Cirrus Logic, Inc.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Authors: Paul Handrigan <Paul.Handrigan@cirrus.com>,
88c2ecf20Sopenharmony_ci *          Tim Howe <Tim.Howe@cirrus.com>
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/clk.h>
128c2ecf20Sopenharmony_ci#include <linux/delay.h>
138c2ecf20Sopenharmony_ci#include <linux/i2c.h>
148c2ecf20Sopenharmony_ci#include <linux/module.h>
158c2ecf20Sopenharmony_ci#include <linux/of_gpio.h>
168c2ecf20Sopenharmony_ci#include <linux/gpio/consumer.h>
178c2ecf20Sopenharmony_ci#include <linux/regulator/consumer.h>
188c2ecf20Sopenharmony_ci#include <sound/pcm_params.h>
198c2ecf20Sopenharmony_ci#include <sound/soc.h>
208c2ecf20Sopenharmony_ci#include <sound/tlv.h>
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include "cs53l30.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define CS53L30_NUM_SUPPLIES 2
258c2ecf20Sopenharmony_cistatic const char *const cs53l30_supply_names[CS53L30_NUM_SUPPLIES] = {
268c2ecf20Sopenharmony_ci	"VA",
278c2ecf20Sopenharmony_ci	"VP",
288c2ecf20Sopenharmony_ci};
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_cistruct cs53l30_private {
318c2ecf20Sopenharmony_ci	struct regulator_bulk_data	supplies[CS53L30_NUM_SUPPLIES];
328c2ecf20Sopenharmony_ci	struct regmap			*regmap;
338c2ecf20Sopenharmony_ci	struct gpio_desc		*reset_gpio;
348c2ecf20Sopenharmony_ci	struct gpio_desc		*mute_gpio;
358c2ecf20Sopenharmony_ci	struct clk			*mclk;
368c2ecf20Sopenharmony_ci	bool				use_sdout2;
378c2ecf20Sopenharmony_ci	u32				mclk_rate;
388c2ecf20Sopenharmony_ci};
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic const struct reg_default cs53l30_reg_defaults[] = {
418c2ecf20Sopenharmony_ci	{ CS53L30_PWRCTL,		CS53L30_PWRCTL_DEFAULT },
428c2ecf20Sopenharmony_ci	{ CS53L30_MCLKCTL,		CS53L30_MCLKCTL_DEFAULT },
438c2ecf20Sopenharmony_ci	{ CS53L30_INT_SR_CTL,		CS53L30_INT_SR_CTL_DEFAULT },
448c2ecf20Sopenharmony_ci	{ CS53L30_MICBIAS_CTL,		CS53L30_MICBIAS_CTL_DEFAULT },
458c2ecf20Sopenharmony_ci	{ CS53L30_ASPCFG_CTL,		CS53L30_ASPCFG_CTL_DEFAULT },
468c2ecf20Sopenharmony_ci	{ CS53L30_ASP_CTL1,		CS53L30_ASP_CTL1_DEFAULT },
478c2ecf20Sopenharmony_ci	{ CS53L30_ASP_TDMTX_CTL1,	CS53L30_ASP_TDMTX_CTLx_DEFAULT },
488c2ecf20Sopenharmony_ci	{ CS53L30_ASP_TDMTX_CTL2,	CS53L30_ASP_TDMTX_CTLx_DEFAULT },
498c2ecf20Sopenharmony_ci	{ CS53L30_ASP_TDMTX_CTL3,	CS53L30_ASP_TDMTX_CTLx_DEFAULT },
508c2ecf20Sopenharmony_ci	{ CS53L30_ASP_TDMTX_CTL4,	CS53L30_ASP_TDMTX_CTLx_DEFAULT },
518c2ecf20Sopenharmony_ci	{ CS53L30_ASP_TDMTX_EN1,	CS53L30_ASP_TDMTX_ENx_DEFAULT },
528c2ecf20Sopenharmony_ci	{ CS53L30_ASP_TDMTX_EN2,	CS53L30_ASP_TDMTX_ENx_DEFAULT },
538c2ecf20Sopenharmony_ci	{ CS53L30_ASP_TDMTX_EN3,	CS53L30_ASP_TDMTX_ENx_DEFAULT },
548c2ecf20Sopenharmony_ci	{ CS53L30_ASP_TDMTX_EN4,	CS53L30_ASP_TDMTX_ENx_DEFAULT },
558c2ecf20Sopenharmony_ci	{ CS53L30_ASP_TDMTX_EN5,	CS53L30_ASP_TDMTX_ENx_DEFAULT },
568c2ecf20Sopenharmony_ci	{ CS53L30_ASP_TDMTX_EN6,	CS53L30_ASP_TDMTX_ENx_DEFAULT },
578c2ecf20Sopenharmony_ci	{ CS53L30_ASP_CTL2,		CS53L30_ASP_CTL2_DEFAULT },
588c2ecf20Sopenharmony_ci	{ CS53L30_SFT_RAMP,		CS53L30_SFT_RMP_DEFAULT },
598c2ecf20Sopenharmony_ci	{ CS53L30_LRCK_CTL1,		CS53L30_LRCK_CTLx_DEFAULT },
608c2ecf20Sopenharmony_ci	{ CS53L30_LRCK_CTL2,		CS53L30_LRCK_CTLx_DEFAULT },
618c2ecf20Sopenharmony_ci	{ CS53L30_MUTEP_CTL1,		CS53L30_MUTEP_CTL1_DEFAULT },
628c2ecf20Sopenharmony_ci	{ CS53L30_MUTEP_CTL2,		CS53L30_MUTEP_CTL2_DEFAULT },
638c2ecf20Sopenharmony_ci	{ CS53L30_INBIAS_CTL1,		CS53L30_INBIAS_CTL1_DEFAULT },
648c2ecf20Sopenharmony_ci	{ CS53L30_INBIAS_CTL2,		CS53L30_INBIAS_CTL2_DEFAULT },
658c2ecf20Sopenharmony_ci	{ CS53L30_DMIC1_STR_CTL,	CS53L30_DMIC1_STR_CTL_DEFAULT },
668c2ecf20Sopenharmony_ci	{ CS53L30_DMIC2_STR_CTL,	CS53L30_DMIC2_STR_CTL_DEFAULT },
678c2ecf20Sopenharmony_ci	{ CS53L30_ADCDMIC1_CTL1,	CS53L30_ADCDMICx_CTL1_DEFAULT },
688c2ecf20Sopenharmony_ci	{ CS53L30_ADCDMIC1_CTL2,	CS53L30_ADCDMIC1_CTL2_DEFAULT },
698c2ecf20Sopenharmony_ci	{ CS53L30_ADC1_CTL3,		CS53L30_ADCx_CTL3_DEFAULT },
708c2ecf20Sopenharmony_ci	{ CS53L30_ADC1_NG_CTL,		CS53L30_ADCx_NG_CTL_DEFAULT },
718c2ecf20Sopenharmony_ci	{ CS53L30_ADC1A_AFE_CTL,	CS53L30_ADCxy_AFE_CTL_DEFAULT },
728c2ecf20Sopenharmony_ci	{ CS53L30_ADC1B_AFE_CTL,	CS53L30_ADCxy_AFE_CTL_DEFAULT },
738c2ecf20Sopenharmony_ci	{ CS53L30_ADC1A_DIG_VOL,	CS53L30_ADCxy_DIG_VOL_DEFAULT },
748c2ecf20Sopenharmony_ci	{ CS53L30_ADC1B_DIG_VOL,	CS53L30_ADCxy_DIG_VOL_DEFAULT },
758c2ecf20Sopenharmony_ci	{ CS53L30_ADCDMIC2_CTL1,	CS53L30_ADCDMICx_CTL1_DEFAULT },
768c2ecf20Sopenharmony_ci	{ CS53L30_ADCDMIC2_CTL2,	CS53L30_ADCDMIC1_CTL2_DEFAULT },
778c2ecf20Sopenharmony_ci	{ CS53L30_ADC2_CTL3,		CS53L30_ADCx_CTL3_DEFAULT },
788c2ecf20Sopenharmony_ci	{ CS53L30_ADC2_NG_CTL,		CS53L30_ADCx_NG_CTL_DEFAULT },
798c2ecf20Sopenharmony_ci	{ CS53L30_ADC2A_AFE_CTL,	CS53L30_ADCxy_AFE_CTL_DEFAULT },
808c2ecf20Sopenharmony_ci	{ CS53L30_ADC2B_AFE_CTL,	CS53L30_ADCxy_AFE_CTL_DEFAULT },
818c2ecf20Sopenharmony_ci	{ CS53L30_ADC2A_DIG_VOL,	CS53L30_ADCxy_DIG_VOL_DEFAULT },
828c2ecf20Sopenharmony_ci	{ CS53L30_ADC2B_DIG_VOL,	CS53L30_ADCxy_DIG_VOL_DEFAULT },
838c2ecf20Sopenharmony_ci	{ CS53L30_INT_MASK,		CS53L30_DEVICE_INT_MASK },
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistatic bool cs53l30_volatile_register(struct device *dev, unsigned int reg)
878c2ecf20Sopenharmony_ci{
888c2ecf20Sopenharmony_ci	if (reg == CS53L30_IS)
898c2ecf20Sopenharmony_ci		return true;
908c2ecf20Sopenharmony_ci	else
918c2ecf20Sopenharmony_ci		return false;
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic bool cs53l30_writeable_register(struct device *dev, unsigned int reg)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	switch (reg) {
978c2ecf20Sopenharmony_ci	case CS53L30_DEVID_AB:
988c2ecf20Sopenharmony_ci	case CS53L30_DEVID_CD:
998c2ecf20Sopenharmony_ci	case CS53L30_DEVID_E:
1008c2ecf20Sopenharmony_ci	case CS53L30_REVID:
1018c2ecf20Sopenharmony_ci	case CS53L30_IS:
1028c2ecf20Sopenharmony_ci		return false;
1038c2ecf20Sopenharmony_ci	default:
1048c2ecf20Sopenharmony_ci		return true;
1058c2ecf20Sopenharmony_ci	}
1068c2ecf20Sopenharmony_ci}
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_cistatic bool cs53l30_readable_register(struct device *dev, unsigned int reg)
1098c2ecf20Sopenharmony_ci{
1108c2ecf20Sopenharmony_ci	switch (reg) {
1118c2ecf20Sopenharmony_ci	case CS53L30_DEVID_AB:
1128c2ecf20Sopenharmony_ci	case CS53L30_DEVID_CD:
1138c2ecf20Sopenharmony_ci	case CS53L30_DEVID_E:
1148c2ecf20Sopenharmony_ci	case CS53L30_REVID:
1158c2ecf20Sopenharmony_ci	case CS53L30_PWRCTL:
1168c2ecf20Sopenharmony_ci	case CS53L30_MCLKCTL:
1178c2ecf20Sopenharmony_ci	case CS53L30_INT_SR_CTL:
1188c2ecf20Sopenharmony_ci	case CS53L30_MICBIAS_CTL:
1198c2ecf20Sopenharmony_ci	case CS53L30_ASPCFG_CTL:
1208c2ecf20Sopenharmony_ci	case CS53L30_ASP_CTL1:
1218c2ecf20Sopenharmony_ci	case CS53L30_ASP_TDMTX_CTL1:
1228c2ecf20Sopenharmony_ci	case CS53L30_ASP_TDMTX_CTL2:
1238c2ecf20Sopenharmony_ci	case CS53L30_ASP_TDMTX_CTL3:
1248c2ecf20Sopenharmony_ci	case CS53L30_ASP_TDMTX_CTL4:
1258c2ecf20Sopenharmony_ci	case CS53L30_ASP_TDMTX_EN1:
1268c2ecf20Sopenharmony_ci	case CS53L30_ASP_TDMTX_EN2:
1278c2ecf20Sopenharmony_ci	case CS53L30_ASP_TDMTX_EN3:
1288c2ecf20Sopenharmony_ci	case CS53L30_ASP_TDMTX_EN4:
1298c2ecf20Sopenharmony_ci	case CS53L30_ASP_TDMTX_EN5:
1308c2ecf20Sopenharmony_ci	case CS53L30_ASP_TDMTX_EN6:
1318c2ecf20Sopenharmony_ci	case CS53L30_ASP_CTL2:
1328c2ecf20Sopenharmony_ci	case CS53L30_SFT_RAMP:
1338c2ecf20Sopenharmony_ci	case CS53L30_LRCK_CTL1:
1348c2ecf20Sopenharmony_ci	case CS53L30_LRCK_CTL2:
1358c2ecf20Sopenharmony_ci	case CS53L30_MUTEP_CTL1:
1368c2ecf20Sopenharmony_ci	case CS53L30_MUTEP_CTL2:
1378c2ecf20Sopenharmony_ci	case CS53L30_INBIAS_CTL1:
1388c2ecf20Sopenharmony_ci	case CS53L30_INBIAS_CTL2:
1398c2ecf20Sopenharmony_ci	case CS53L30_DMIC1_STR_CTL:
1408c2ecf20Sopenharmony_ci	case CS53L30_DMIC2_STR_CTL:
1418c2ecf20Sopenharmony_ci	case CS53L30_ADCDMIC1_CTL1:
1428c2ecf20Sopenharmony_ci	case CS53L30_ADCDMIC1_CTL2:
1438c2ecf20Sopenharmony_ci	case CS53L30_ADC1_CTL3:
1448c2ecf20Sopenharmony_ci	case CS53L30_ADC1_NG_CTL:
1458c2ecf20Sopenharmony_ci	case CS53L30_ADC1A_AFE_CTL:
1468c2ecf20Sopenharmony_ci	case CS53L30_ADC1B_AFE_CTL:
1478c2ecf20Sopenharmony_ci	case CS53L30_ADC1A_DIG_VOL:
1488c2ecf20Sopenharmony_ci	case CS53L30_ADC1B_DIG_VOL:
1498c2ecf20Sopenharmony_ci	case CS53L30_ADCDMIC2_CTL1:
1508c2ecf20Sopenharmony_ci	case CS53L30_ADCDMIC2_CTL2:
1518c2ecf20Sopenharmony_ci	case CS53L30_ADC2_CTL3:
1528c2ecf20Sopenharmony_ci	case CS53L30_ADC2_NG_CTL:
1538c2ecf20Sopenharmony_ci	case CS53L30_ADC2A_AFE_CTL:
1548c2ecf20Sopenharmony_ci	case CS53L30_ADC2B_AFE_CTL:
1558c2ecf20Sopenharmony_ci	case CS53L30_ADC2A_DIG_VOL:
1568c2ecf20Sopenharmony_ci	case CS53L30_ADC2B_DIG_VOL:
1578c2ecf20Sopenharmony_ci	case CS53L30_INT_MASK:
1588c2ecf20Sopenharmony_ci		return true;
1598c2ecf20Sopenharmony_ci	default:
1608c2ecf20Sopenharmony_ci		return false;
1618c2ecf20Sopenharmony_ci	}
1628c2ecf20Sopenharmony_ci}
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_cistatic DECLARE_TLV_DB_SCALE(adc_boost_tlv, 0, 2000, 0);
1658c2ecf20Sopenharmony_cistatic DECLARE_TLV_DB_SCALE(adc_ng_boost_tlv, 0, 3000, 0);
1668c2ecf20Sopenharmony_cistatic DECLARE_TLV_DB_SCALE(pga_tlv, -600, 50, 0);
1678c2ecf20Sopenharmony_cistatic DECLARE_TLV_DB_SCALE(dig_tlv, -9600, 100, 1);
1688c2ecf20Sopenharmony_cistatic DECLARE_TLV_DB_SCALE(pga_preamp_tlv, 0, 10000, 0);
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cistatic const char * const input1_sel_text[] = {
1718c2ecf20Sopenharmony_ci	"DMIC1 On AB In",
1728c2ecf20Sopenharmony_ci	"DMIC1 On A In",
1738c2ecf20Sopenharmony_ci	"DMIC1 On B In",
1748c2ecf20Sopenharmony_ci	"ADC1 On AB In",
1758c2ecf20Sopenharmony_ci	"ADC1 On A In",
1768c2ecf20Sopenharmony_ci	"ADC1 On B In",
1778c2ecf20Sopenharmony_ci	"DMIC1 Off ADC1 Off",
1788c2ecf20Sopenharmony_ci};
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic unsigned int const input1_sel_values[] = {
1818c2ecf20Sopenharmony_ci	CS53L30_CH_TYPE,
1828c2ecf20Sopenharmony_ci	CS53L30_ADCxB_PDN | CS53L30_CH_TYPE,
1838c2ecf20Sopenharmony_ci	CS53L30_ADCxA_PDN | CS53L30_CH_TYPE,
1848c2ecf20Sopenharmony_ci	CS53L30_DMICx_PDN,
1858c2ecf20Sopenharmony_ci	CS53L30_ADCxB_PDN | CS53L30_DMICx_PDN,
1868c2ecf20Sopenharmony_ci	CS53L30_ADCxA_PDN | CS53L30_DMICx_PDN,
1878c2ecf20Sopenharmony_ci	CS53L30_ADCxA_PDN | CS53L30_ADCxB_PDN | CS53L30_DMICx_PDN,
1888c2ecf20Sopenharmony_ci};
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_cistatic const char * const input2_sel_text[] = {
1918c2ecf20Sopenharmony_ci	"DMIC2 On AB In",
1928c2ecf20Sopenharmony_ci	"DMIC2 On A In",
1938c2ecf20Sopenharmony_ci	"DMIC2 On B In",
1948c2ecf20Sopenharmony_ci	"ADC2 On AB In",
1958c2ecf20Sopenharmony_ci	"ADC2 On A In",
1968c2ecf20Sopenharmony_ci	"ADC2 On B In",
1978c2ecf20Sopenharmony_ci	"DMIC2 Off ADC2 Off",
1988c2ecf20Sopenharmony_ci};
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_cistatic unsigned int const input2_sel_values[] = {
2018c2ecf20Sopenharmony_ci	0x0,
2028c2ecf20Sopenharmony_ci	CS53L30_ADCxB_PDN,
2038c2ecf20Sopenharmony_ci	CS53L30_ADCxA_PDN,
2048c2ecf20Sopenharmony_ci	CS53L30_DMICx_PDN,
2058c2ecf20Sopenharmony_ci	CS53L30_ADCxB_PDN | CS53L30_DMICx_PDN,
2068c2ecf20Sopenharmony_ci	CS53L30_ADCxA_PDN | CS53L30_DMICx_PDN,
2078c2ecf20Sopenharmony_ci	CS53L30_ADCxA_PDN | CS53L30_ADCxB_PDN | CS53L30_DMICx_PDN,
2088c2ecf20Sopenharmony_ci};
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_cistatic const char * const input1_route_sel_text[] = {
2118c2ecf20Sopenharmony_ci	"ADC1_SEL", "DMIC1_SEL",
2128c2ecf20Sopenharmony_ci};
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_cistatic const struct soc_enum input1_route_sel_enum =
2158c2ecf20Sopenharmony_ci	SOC_ENUM_SINGLE(CS53L30_ADCDMIC1_CTL1, CS53L30_CH_TYPE_SHIFT,
2168c2ecf20Sopenharmony_ci			ARRAY_SIZE(input1_route_sel_text),
2178c2ecf20Sopenharmony_ci			input1_route_sel_text);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(input1_sel_enum, CS53L30_ADCDMIC1_CTL1, 0,
2208c2ecf20Sopenharmony_ci				  CS53L30_ADCDMICx_PDN_MASK, input1_sel_text,
2218c2ecf20Sopenharmony_ci				  input1_sel_values);
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new input1_route_sel_mux =
2248c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("Input 1 Route", input1_route_sel_enum);
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_cistatic const char * const input2_route_sel_text[] = {
2278c2ecf20Sopenharmony_ci	"ADC2_SEL", "DMIC2_SEL",
2288c2ecf20Sopenharmony_ci};
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci/* Note: CS53L30_ADCDMIC1_CTL1 CH_TYPE controls inputs 1 and 2 */
2318c2ecf20Sopenharmony_cistatic const struct soc_enum input2_route_sel_enum =
2328c2ecf20Sopenharmony_ci	SOC_ENUM_SINGLE(CS53L30_ADCDMIC1_CTL1, 0,
2338c2ecf20Sopenharmony_ci			ARRAY_SIZE(input2_route_sel_text),
2348c2ecf20Sopenharmony_ci			input2_route_sel_text);
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_cistatic SOC_VALUE_ENUM_SINGLE_DECL(input2_sel_enum, CS53L30_ADCDMIC2_CTL1, 0,
2378c2ecf20Sopenharmony_ci				  CS53L30_ADCDMICx_PDN_MASK, input2_sel_text,
2388c2ecf20Sopenharmony_ci				  input2_sel_values);
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new input2_route_sel_mux =
2418c2ecf20Sopenharmony_ci	SOC_DAPM_ENUM("Input 2 Route", input2_route_sel_enum);
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci/*
2448c2ecf20Sopenharmony_ci * TB = 6144*(MCLK(int) scaling factor)/MCLK(internal)
2458c2ecf20Sopenharmony_ci * TB - Time base
2468c2ecf20Sopenharmony_ci * NOTE: If MCLK_INT_SCALE = 0, then TB=1
2478c2ecf20Sopenharmony_ci */
2488c2ecf20Sopenharmony_cistatic const char * const cs53l30_ng_delay_text[] = {
2498c2ecf20Sopenharmony_ci	"TB*50ms", "TB*100ms", "TB*150ms", "TB*200ms",
2508c2ecf20Sopenharmony_ci};
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_cistatic const struct soc_enum adc1_ng_delay_enum =
2538c2ecf20Sopenharmony_ci	SOC_ENUM_SINGLE(CS53L30_ADC1_NG_CTL, CS53L30_ADCx_NG_DELAY_SHIFT,
2548c2ecf20Sopenharmony_ci			ARRAY_SIZE(cs53l30_ng_delay_text),
2558c2ecf20Sopenharmony_ci			cs53l30_ng_delay_text);
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_cistatic const struct soc_enum adc2_ng_delay_enum =
2588c2ecf20Sopenharmony_ci	SOC_ENUM_SINGLE(CS53L30_ADC2_NG_CTL, CS53L30_ADCx_NG_DELAY_SHIFT,
2598c2ecf20Sopenharmony_ci			ARRAY_SIZE(cs53l30_ng_delay_text),
2608c2ecf20Sopenharmony_ci			cs53l30_ng_delay_text);
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_ci/* The noise gate threshold selected will depend on NG Boost */
2638c2ecf20Sopenharmony_cistatic const char * const cs53l30_ng_thres_text[] = {
2648c2ecf20Sopenharmony_ci	"-64dB/-34dB", "-66dB/-36dB", "-70dB/-40dB", "-73dB/-43dB",
2658c2ecf20Sopenharmony_ci	"-76dB/-46dB", "-82dB/-52dB", "-58dB", "-64dB",
2668c2ecf20Sopenharmony_ci};
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_cistatic const struct soc_enum adc1_ng_thres_enum =
2698c2ecf20Sopenharmony_ci	SOC_ENUM_SINGLE(CS53L30_ADC1_NG_CTL, CS53L30_ADCx_NG_THRESH_SHIFT,
2708c2ecf20Sopenharmony_ci			ARRAY_SIZE(cs53l30_ng_thres_text),
2718c2ecf20Sopenharmony_ci			cs53l30_ng_thres_text);
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_cistatic const struct soc_enum adc2_ng_thres_enum =
2748c2ecf20Sopenharmony_ci	SOC_ENUM_SINGLE(CS53L30_ADC2_NG_CTL, CS53L30_ADCx_NG_THRESH_SHIFT,
2758c2ecf20Sopenharmony_ci			ARRAY_SIZE(cs53l30_ng_thres_text),
2768c2ecf20Sopenharmony_ci			cs53l30_ng_thres_text);
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci/* Corner frequencies are with an Fs of 48kHz. */
2798c2ecf20Sopenharmony_cistatic const char * const hpf_corner_freq_text[] = {
2808c2ecf20Sopenharmony_ci	"1.86Hz", "120Hz", "235Hz", "466Hz",
2818c2ecf20Sopenharmony_ci};
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_cistatic const struct soc_enum adc1_hpf_enum =
2848c2ecf20Sopenharmony_ci	SOC_ENUM_SINGLE(CS53L30_ADC1_CTL3, CS53L30_ADCx_HPF_CF_SHIFT,
2858c2ecf20Sopenharmony_ci			ARRAY_SIZE(hpf_corner_freq_text), hpf_corner_freq_text);
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_cistatic const struct soc_enum adc2_hpf_enum =
2888c2ecf20Sopenharmony_ci	SOC_ENUM_SINGLE(CS53L30_ADC2_CTL3, CS53L30_ADCx_HPF_CF_SHIFT,
2898c2ecf20Sopenharmony_ci			ARRAY_SIZE(hpf_corner_freq_text), hpf_corner_freq_text);
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_cistatic const struct snd_kcontrol_new cs53l30_snd_controls[] = {
2928c2ecf20Sopenharmony_ci	SOC_SINGLE("Digital Soft-Ramp Switch", CS53L30_SFT_RAMP,
2938c2ecf20Sopenharmony_ci		   CS53L30_DIGSFT_SHIFT, 1, 0),
2948c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC1 Noise Gate Ganging Switch", CS53L30_ADC1_CTL3,
2958c2ecf20Sopenharmony_ci		   CS53L30_ADCx_NG_ALL_SHIFT, 1, 0),
2968c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC2 Noise Gate Ganging Switch", CS53L30_ADC2_CTL3,
2978c2ecf20Sopenharmony_ci		   CS53L30_ADCx_NG_ALL_SHIFT, 1, 0),
2988c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC1A Noise Gate Enable Switch", CS53L30_ADC1_NG_CTL,
2998c2ecf20Sopenharmony_ci		   CS53L30_ADCxA_NG_SHIFT, 1, 0),
3008c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC1B Noise Gate Enable Switch", CS53L30_ADC1_NG_CTL,
3018c2ecf20Sopenharmony_ci		   CS53L30_ADCxB_NG_SHIFT, 1, 0),
3028c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC2A Noise Gate Enable Switch", CS53L30_ADC2_NG_CTL,
3038c2ecf20Sopenharmony_ci		   CS53L30_ADCxA_NG_SHIFT, 1, 0),
3048c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC2B Noise Gate Enable Switch", CS53L30_ADC2_NG_CTL,
3058c2ecf20Sopenharmony_ci		   CS53L30_ADCxB_NG_SHIFT, 1, 0),
3068c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC1 Notch Filter Switch", CS53L30_ADCDMIC1_CTL2,
3078c2ecf20Sopenharmony_ci		   CS53L30_ADCx_NOTCH_DIS_SHIFT, 1, 1),
3088c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC2 Notch Filter Switch", CS53L30_ADCDMIC2_CTL2,
3098c2ecf20Sopenharmony_ci		   CS53L30_ADCx_NOTCH_DIS_SHIFT, 1, 1),
3108c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC1A Invert Switch", CS53L30_ADCDMIC1_CTL2,
3118c2ecf20Sopenharmony_ci		   CS53L30_ADCxA_INV_SHIFT, 1, 0),
3128c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC1B Invert Switch", CS53L30_ADCDMIC1_CTL2,
3138c2ecf20Sopenharmony_ci		   CS53L30_ADCxB_INV_SHIFT, 1, 0),
3148c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC2A Invert Switch", CS53L30_ADCDMIC2_CTL2,
3158c2ecf20Sopenharmony_ci		   CS53L30_ADCxA_INV_SHIFT, 1, 0),
3168c2ecf20Sopenharmony_ci	SOC_SINGLE("ADC2B Invert Switch", CS53L30_ADCDMIC2_CTL2,
3178c2ecf20Sopenharmony_ci		   CS53L30_ADCxB_INV_SHIFT, 1, 0),
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ADC1A Digital Boost Volume", CS53L30_ADCDMIC1_CTL2,
3208c2ecf20Sopenharmony_ci		       CS53L30_ADCxA_DIG_BOOST_SHIFT, 1, 0, adc_boost_tlv),
3218c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ADC1B Digital Boost Volume", CS53L30_ADCDMIC1_CTL2,
3228c2ecf20Sopenharmony_ci		       CS53L30_ADCxB_DIG_BOOST_SHIFT, 1, 0, adc_boost_tlv),
3238c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ADC2A Digital Boost Volume", CS53L30_ADCDMIC2_CTL2,
3248c2ecf20Sopenharmony_ci		       CS53L30_ADCxA_DIG_BOOST_SHIFT, 1, 0, adc_boost_tlv),
3258c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ADC2B Digital Boost Volume", CS53L30_ADCDMIC2_CTL2,
3268c2ecf20Sopenharmony_ci		       CS53L30_ADCxB_DIG_BOOST_SHIFT, 1, 0, adc_boost_tlv),
3278c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ADC1 NG Boost Volume", CS53L30_ADC1_NG_CTL,
3288c2ecf20Sopenharmony_ci		       CS53L30_ADCx_NG_BOOST_SHIFT, 1, 0, adc_ng_boost_tlv),
3298c2ecf20Sopenharmony_ci	SOC_SINGLE_TLV("ADC2 NG Boost Volume", CS53L30_ADC2_NG_CTL,
3308c2ecf20Sopenharmony_ci		       CS53L30_ADCx_NG_BOOST_SHIFT, 1, 0, adc_ng_boost_tlv),
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("ADC1 Preamplifier Volume", CS53L30_ADC1A_AFE_CTL,
3338c2ecf20Sopenharmony_ci			 CS53L30_ADC1B_AFE_CTL, CS53L30_ADCxy_PREAMP_SHIFT,
3348c2ecf20Sopenharmony_ci			 2, 0, pga_preamp_tlv),
3358c2ecf20Sopenharmony_ci	SOC_DOUBLE_R_TLV("ADC2 Preamplifier Volume", CS53L30_ADC2A_AFE_CTL,
3368c2ecf20Sopenharmony_ci			 CS53L30_ADC2B_AFE_CTL, CS53L30_ADCxy_PREAMP_SHIFT,
3378c2ecf20Sopenharmony_ci			 2, 0, pga_preamp_tlv),
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	SOC_ENUM("Input 1 Channel Select", input1_sel_enum),
3408c2ecf20Sopenharmony_ci	SOC_ENUM("Input 2 Channel Select", input2_sel_enum),
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_ci	SOC_ENUM("ADC1 HPF Select", adc1_hpf_enum),
3438c2ecf20Sopenharmony_ci	SOC_ENUM("ADC2 HPF Select", adc2_hpf_enum),
3448c2ecf20Sopenharmony_ci	SOC_ENUM("ADC1 NG Threshold", adc1_ng_thres_enum),
3458c2ecf20Sopenharmony_ci	SOC_ENUM("ADC2 NG Threshold", adc2_ng_thres_enum),
3468c2ecf20Sopenharmony_ci	SOC_ENUM("ADC1 NG Delay", adc1_ng_delay_enum),
3478c2ecf20Sopenharmony_ci	SOC_ENUM("ADC2 NG Delay", adc2_ng_delay_enum),
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	SOC_SINGLE_SX_TLV("ADC1A PGA Volume",
3508c2ecf20Sopenharmony_ci		    CS53L30_ADC1A_AFE_CTL, 0, 0x34, 0x24, pga_tlv),
3518c2ecf20Sopenharmony_ci	SOC_SINGLE_SX_TLV("ADC1B PGA Volume",
3528c2ecf20Sopenharmony_ci		    CS53L30_ADC1B_AFE_CTL, 0, 0x34, 0x24, pga_tlv),
3538c2ecf20Sopenharmony_ci	SOC_SINGLE_SX_TLV("ADC2A PGA Volume",
3548c2ecf20Sopenharmony_ci		    CS53L30_ADC2A_AFE_CTL, 0, 0x34, 0x24, pga_tlv),
3558c2ecf20Sopenharmony_ci	SOC_SINGLE_SX_TLV("ADC2B PGA Volume",
3568c2ecf20Sopenharmony_ci		    CS53L30_ADC2B_AFE_CTL, 0, 0x34, 0x24, pga_tlv),
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	SOC_SINGLE_SX_TLV("ADC1A Digital Volume",
3598c2ecf20Sopenharmony_ci		    CS53L30_ADC1A_DIG_VOL, 0, 0xA0, 0x6C, dig_tlv),
3608c2ecf20Sopenharmony_ci	SOC_SINGLE_SX_TLV("ADC1B Digital Volume",
3618c2ecf20Sopenharmony_ci		    CS53L30_ADC1B_DIG_VOL, 0, 0xA0, 0x6C, dig_tlv),
3628c2ecf20Sopenharmony_ci	SOC_SINGLE_SX_TLV("ADC2A Digital Volume",
3638c2ecf20Sopenharmony_ci		    CS53L30_ADC2A_DIG_VOL, 0, 0xA0, 0x6C, dig_tlv),
3648c2ecf20Sopenharmony_ci	SOC_SINGLE_SX_TLV("ADC2B Digital Volume",
3658c2ecf20Sopenharmony_ci		    CS53L30_ADC2B_DIG_VOL, 0, 0xA0, 0x6C, dig_tlv),
3668c2ecf20Sopenharmony_ci};
3678c2ecf20Sopenharmony_ci
3688c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_widget cs53l30_dapm_widgets[] = {
3698c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("IN1_DMIC1"),
3708c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("IN2"),
3718c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("IN3_DMIC2"),
3728c2ecf20Sopenharmony_ci	SND_SOC_DAPM_INPUT("IN4"),
3738c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC1 Bias", CS53L30_MICBIAS_CTL,
3748c2ecf20Sopenharmony_ci			    CS53L30_MIC1_BIAS_PDN_SHIFT, 1, NULL, 0),
3758c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC2 Bias", CS53L30_MICBIAS_CTL,
3768c2ecf20Sopenharmony_ci			    CS53L30_MIC2_BIAS_PDN_SHIFT, 1, NULL, 0),
3778c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC3 Bias", CS53L30_MICBIAS_CTL,
3788c2ecf20Sopenharmony_ci			    CS53L30_MIC3_BIAS_PDN_SHIFT, 1, NULL, 0),
3798c2ecf20Sopenharmony_ci	SND_SOC_DAPM_SUPPLY("MIC4 Bias", CS53L30_MICBIAS_CTL,
3808c2ecf20Sopenharmony_ci			    CS53L30_MIC4_BIAS_PDN_SHIFT, 1, NULL, 0),
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci	SND_SOC_DAPM_AIF_OUT("ASP_SDOUT1", NULL, 0, CS53L30_ASP_CTL1,
3838c2ecf20Sopenharmony_ci			     CS53L30_ASP_SDOUTx_PDN_SHIFT, 1),
3848c2ecf20Sopenharmony_ci	SND_SOC_DAPM_AIF_OUT("ASP_SDOUT2", NULL, 0, CS53L30_ASP_CTL2,
3858c2ecf20Sopenharmony_ci			     CS53L30_ASP_SDOUTx_PDN_SHIFT, 1),
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("Input Mux 1", SND_SOC_NOPM, 0, 0,
3888c2ecf20Sopenharmony_ci			 &input1_route_sel_mux),
3898c2ecf20Sopenharmony_ci	SND_SOC_DAPM_MUX("Input Mux 2", SND_SOC_NOPM, 0, 0,
3908c2ecf20Sopenharmony_ci			 &input2_route_sel_mux),
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("ADC1A", NULL, CS53L30_ADCDMIC1_CTL1,
3938c2ecf20Sopenharmony_ci			 CS53L30_ADCxA_PDN_SHIFT, 1),
3948c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("ADC1B", NULL, CS53L30_ADCDMIC1_CTL1,
3958c2ecf20Sopenharmony_ci			 CS53L30_ADCxB_PDN_SHIFT, 1),
3968c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("ADC2A", NULL, CS53L30_ADCDMIC2_CTL1,
3978c2ecf20Sopenharmony_ci			 CS53L30_ADCxA_PDN_SHIFT, 1),
3988c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("ADC2B", NULL, CS53L30_ADCDMIC2_CTL1,
3998c2ecf20Sopenharmony_ci			 CS53L30_ADCxB_PDN_SHIFT, 1),
4008c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("DMIC1", NULL, CS53L30_ADCDMIC1_CTL1,
4018c2ecf20Sopenharmony_ci			 CS53L30_DMICx_PDN_SHIFT, 1),
4028c2ecf20Sopenharmony_ci	SND_SOC_DAPM_ADC("DMIC2", NULL, CS53L30_ADCDMIC2_CTL1,
4038c2ecf20Sopenharmony_ci			 CS53L30_DMICx_PDN_SHIFT, 1),
4048c2ecf20Sopenharmony_ci};
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route cs53l30_dapm_routes[] = {
4078c2ecf20Sopenharmony_ci	/* ADC Input Paths */
4088c2ecf20Sopenharmony_ci	{"ADC1A", NULL, "IN1_DMIC1"},
4098c2ecf20Sopenharmony_ci	{"Input Mux 1", "ADC1_SEL", "ADC1A"},
4108c2ecf20Sopenharmony_ci	{"ADC1B", NULL, "IN2"},
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_ci	{"ADC2A", NULL, "IN3_DMIC2"},
4138c2ecf20Sopenharmony_ci	{"Input Mux 2", "ADC2_SEL", "ADC2A"},
4148c2ecf20Sopenharmony_ci	{"ADC2B", NULL, "IN4"},
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ci	/* MIC Bias Paths */
4178c2ecf20Sopenharmony_ci	{"ADC1A", NULL, "MIC1 Bias"},
4188c2ecf20Sopenharmony_ci	{"ADC1B", NULL, "MIC2 Bias"},
4198c2ecf20Sopenharmony_ci	{"ADC2A", NULL, "MIC3 Bias"},
4208c2ecf20Sopenharmony_ci	{"ADC2B", NULL, "MIC4 Bias"},
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	/* DMIC Paths */
4238c2ecf20Sopenharmony_ci	{"DMIC1", NULL, "IN1_DMIC1"},
4248c2ecf20Sopenharmony_ci	{"Input Mux 1", "DMIC1_SEL", "DMIC1"},
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_ci	{"DMIC2", NULL, "IN3_DMIC2"},
4278c2ecf20Sopenharmony_ci	{"Input Mux 2", "DMIC2_SEL", "DMIC2"},
4288c2ecf20Sopenharmony_ci};
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route cs53l30_dapm_routes_sdout1[] = {
4318c2ecf20Sopenharmony_ci	/* Output Paths when using SDOUT1 only */
4328c2ecf20Sopenharmony_ci	{"ASP_SDOUT1", NULL, "ADC1A" },
4338c2ecf20Sopenharmony_ci	{"ASP_SDOUT1", NULL, "Input Mux 1"},
4348c2ecf20Sopenharmony_ci	{"ASP_SDOUT1", NULL, "ADC1B"},
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci	{"ASP_SDOUT1", NULL, "ADC2A"},
4378c2ecf20Sopenharmony_ci	{"ASP_SDOUT1", NULL, "Input Mux 2"},
4388c2ecf20Sopenharmony_ci	{"ASP_SDOUT1", NULL, "ADC2B"},
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_ci	{"Capture", NULL, "ASP_SDOUT1"},
4418c2ecf20Sopenharmony_ci};
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_cistatic const struct snd_soc_dapm_route cs53l30_dapm_routes_sdout2[] = {
4448c2ecf20Sopenharmony_ci	/* Output Paths when using both SDOUT1 and SDOUT2 */
4458c2ecf20Sopenharmony_ci	{"ASP_SDOUT1", NULL, "ADC1A" },
4468c2ecf20Sopenharmony_ci	{"ASP_SDOUT1", NULL, "Input Mux 1"},
4478c2ecf20Sopenharmony_ci	{"ASP_SDOUT1", NULL, "ADC1B"},
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci	{"ASP_SDOUT2", NULL, "ADC2A"},
4508c2ecf20Sopenharmony_ci	{"ASP_SDOUT2", NULL, "Input Mux 2"},
4518c2ecf20Sopenharmony_ci	{"ASP_SDOUT2", NULL, "ADC2B"},
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_ci	{"Capture", NULL, "ASP_SDOUT1"},
4548c2ecf20Sopenharmony_ci	{"Capture", NULL, "ASP_SDOUT2"},
4558c2ecf20Sopenharmony_ci};
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_cistruct cs53l30_mclk_div {
4588c2ecf20Sopenharmony_ci	u32 mclk_rate;
4598c2ecf20Sopenharmony_ci	u32 srate;
4608c2ecf20Sopenharmony_ci	u8 asp_rate;
4618c2ecf20Sopenharmony_ci	u8 internal_fs_ratio;
4628c2ecf20Sopenharmony_ci	u8 mclk_int_scale;
4638c2ecf20Sopenharmony_ci};
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_cistatic const struct cs53l30_mclk_div cs53l30_mclk_coeffs[] = {
4668c2ecf20Sopenharmony_ci	/* NOTE: Enable MCLK_INT_SCALE to save power. */
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_ci	/* MCLK, Sample Rate, asp_rate, internal_fs_ratio, mclk_int_scale */
4698c2ecf20Sopenharmony_ci	{5644800, 11025, 0x4, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4708c2ecf20Sopenharmony_ci	{5644800, 22050, 0x8, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4718c2ecf20Sopenharmony_ci	{5644800, 44100, 0xC, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_ci	{6000000,  8000, 0x1, 0, CS53L30_MCLK_INT_SCALE},
4748c2ecf20Sopenharmony_ci	{6000000, 11025, 0x2, 0, CS53L30_MCLK_INT_SCALE},
4758c2ecf20Sopenharmony_ci	{6000000, 12000, 0x4, 0, CS53L30_MCLK_INT_SCALE},
4768c2ecf20Sopenharmony_ci	{6000000, 16000, 0x5, 0, CS53L30_MCLK_INT_SCALE},
4778c2ecf20Sopenharmony_ci	{6000000, 22050, 0x6, 0, CS53L30_MCLK_INT_SCALE},
4788c2ecf20Sopenharmony_ci	{6000000, 24000, 0x8, 0, CS53L30_MCLK_INT_SCALE},
4798c2ecf20Sopenharmony_ci	{6000000, 32000, 0x9, 0, CS53L30_MCLK_INT_SCALE},
4808c2ecf20Sopenharmony_ci	{6000000, 44100, 0xA, 0, CS53L30_MCLK_INT_SCALE},
4818c2ecf20Sopenharmony_ci	{6000000, 48000, 0xC, 0, CS53L30_MCLK_INT_SCALE},
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci	{6144000,  8000, 0x1, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4848c2ecf20Sopenharmony_ci	{6144000, 11025, 0x2, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4858c2ecf20Sopenharmony_ci	{6144000, 12000, 0x4, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4868c2ecf20Sopenharmony_ci	{6144000, 16000, 0x5, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4878c2ecf20Sopenharmony_ci	{6144000, 22050, 0x6, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4888c2ecf20Sopenharmony_ci	{6144000, 24000, 0x8, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4898c2ecf20Sopenharmony_ci	{6144000, 32000, 0x9, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4908c2ecf20Sopenharmony_ci	{6144000, 44100, 0xA, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4918c2ecf20Sopenharmony_ci	{6144000, 48000, 0xC, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci	{6400000,  8000, 0x1, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4948c2ecf20Sopenharmony_ci	{6400000, 11025, 0x2, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4958c2ecf20Sopenharmony_ci	{6400000, 12000, 0x4, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4968c2ecf20Sopenharmony_ci	{6400000, 16000, 0x5, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4978c2ecf20Sopenharmony_ci	{6400000, 22050, 0x6, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4988c2ecf20Sopenharmony_ci	{6400000, 24000, 0x8, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
4998c2ecf20Sopenharmony_ci	{6400000, 32000, 0x9, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
5008c2ecf20Sopenharmony_ci	{6400000, 44100, 0xA, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
5018c2ecf20Sopenharmony_ci	{6400000, 48000, 0xC, CS53L30_INTRNL_FS_RATIO, CS53L30_MCLK_INT_SCALE},
5028c2ecf20Sopenharmony_ci};
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_cistruct cs53l30_mclkx_div {
5058c2ecf20Sopenharmony_ci	u32 mclkx;
5068c2ecf20Sopenharmony_ci	u8 ratio;
5078c2ecf20Sopenharmony_ci	u8 mclkdiv;
5088c2ecf20Sopenharmony_ci};
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_cistatic const struct cs53l30_mclkx_div cs53l30_mclkx_coeffs[] = {
5118c2ecf20Sopenharmony_ci	{5644800,  1, CS53L30_MCLK_DIV_BY_1},
5128c2ecf20Sopenharmony_ci	{6000000,  1, CS53L30_MCLK_DIV_BY_1},
5138c2ecf20Sopenharmony_ci	{6144000,  1, CS53L30_MCLK_DIV_BY_1},
5148c2ecf20Sopenharmony_ci	{11289600, 2, CS53L30_MCLK_DIV_BY_2},
5158c2ecf20Sopenharmony_ci	{12288000, 2, CS53L30_MCLK_DIV_BY_2},
5168c2ecf20Sopenharmony_ci	{12000000, 2, CS53L30_MCLK_DIV_BY_2},
5178c2ecf20Sopenharmony_ci	{19200000, 3, CS53L30_MCLK_DIV_BY_3},
5188c2ecf20Sopenharmony_ci};
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_cistatic int cs53l30_get_mclkx_coeff(int mclkx)
5218c2ecf20Sopenharmony_ci{
5228c2ecf20Sopenharmony_ci	int i;
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(cs53l30_mclkx_coeffs); i++) {
5258c2ecf20Sopenharmony_ci		if (cs53l30_mclkx_coeffs[i].mclkx == mclkx)
5268c2ecf20Sopenharmony_ci			return i;
5278c2ecf20Sopenharmony_ci	}
5288c2ecf20Sopenharmony_ci
5298c2ecf20Sopenharmony_ci	return -EINVAL;
5308c2ecf20Sopenharmony_ci}
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_cistatic int cs53l30_get_mclk_coeff(int mclk_rate, int srate)
5338c2ecf20Sopenharmony_ci{
5348c2ecf20Sopenharmony_ci	int i;
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(cs53l30_mclk_coeffs); i++) {
5378c2ecf20Sopenharmony_ci		if (cs53l30_mclk_coeffs[i].mclk_rate == mclk_rate &&
5388c2ecf20Sopenharmony_ci		    cs53l30_mclk_coeffs[i].srate == srate)
5398c2ecf20Sopenharmony_ci			return i;
5408c2ecf20Sopenharmony_ci	}
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_ci	return -EINVAL;
5438c2ecf20Sopenharmony_ci}
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_cistatic int cs53l30_set_sysclk(struct snd_soc_dai *dai,
5468c2ecf20Sopenharmony_ci			      int clk_id, unsigned int freq, int dir)
5478c2ecf20Sopenharmony_ci{
5488c2ecf20Sopenharmony_ci	struct cs53l30_private *priv = snd_soc_component_get_drvdata(dai->component);
5498c2ecf20Sopenharmony_ci	int mclkx_coeff;
5508c2ecf20Sopenharmony_ci	u32 mclk_rate;
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci	/* MCLKX -> MCLK */
5538c2ecf20Sopenharmony_ci	mclkx_coeff = cs53l30_get_mclkx_coeff(freq);
5548c2ecf20Sopenharmony_ci	if (mclkx_coeff < 0)
5558c2ecf20Sopenharmony_ci		return mclkx_coeff;
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_ci	mclk_rate = cs53l30_mclkx_coeffs[mclkx_coeff].mclkx /
5588c2ecf20Sopenharmony_ci		    cs53l30_mclkx_coeffs[mclkx_coeff].ratio;
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, CS53L30_MCLKCTL,
5618c2ecf20Sopenharmony_ci			   CS53L30_MCLK_DIV_MASK,
5628c2ecf20Sopenharmony_ci			   cs53l30_mclkx_coeffs[mclkx_coeff].mclkdiv);
5638c2ecf20Sopenharmony_ci
5648c2ecf20Sopenharmony_ci	priv->mclk_rate = mclk_rate;
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci	return 0;
5678c2ecf20Sopenharmony_ci}
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_cistatic int cs53l30_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
5708c2ecf20Sopenharmony_ci{
5718c2ecf20Sopenharmony_ci	struct cs53l30_private *priv = snd_soc_component_get_drvdata(dai->component);
5728c2ecf20Sopenharmony_ci	u8 aspcfg = 0, aspctl1 = 0;
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_ci	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
5758c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_CBM_CFM:
5768c2ecf20Sopenharmony_ci		aspcfg |= CS53L30_ASP_MS;
5778c2ecf20Sopenharmony_ci		break;
5788c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_CBS_CFS:
5798c2ecf20Sopenharmony_ci		break;
5808c2ecf20Sopenharmony_ci	default:
5818c2ecf20Sopenharmony_ci		return -EINVAL;
5828c2ecf20Sopenharmony_ci	}
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_ci	/* DAI mode */
5858c2ecf20Sopenharmony_ci	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
5868c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_I2S:
5878c2ecf20Sopenharmony_ci		/* Set TDM_PDN to turn off TDM mode -- Reset default */
5888c2ecf20Sopenharmony_ci		aspctl1 |= CS53L30_ASP_TDM_PDN;
5898c2ecf20Sopenharmony_ci		break;
5908c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_DSP_A:
5918c2ecf20Sopenharmony_ci		/*
5928c2ecf20Sopenharmony_ci		 * Clear TDM_PDN to turn on TDM mode; Use ASP_SCLK_INV = 0
5938c2ecf20Sopenharmony_ci		 * with SHIFT_LEFT = 1 combination as Figure 4-13 shows in
5948c2ecf20Sopenharmony_ci		 * the CS53L30 datasheet
5958c2ecf20Sopenharmony_ci		 */
5968c2ecf20Sopenharmony_ci		aspctl1 |= CS53L30_SHIFT_LEFT;
5978c2ecf20Sopenharmony_ci		break;
5988c2ecf20Sopenharmony_ci	default:
5998c2ecf20Sopenharmony_ci		return -EINVAL;
6008c2ecf20Sopenharmony_ci	}
6018c2ecf20Sopenharmony_ci
6028c2ecf20Sopenharmony_ci	/* Check to see if the SCLK is inverted */
6038c2ecf20Sopenharmony_ci	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
6048c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_IB_NF:
6058c2ecf20Sopenharmony_ci	case SND_SOC_DAIFMT_IB_IF:
6068c2ecf20Sopenharmony_ci		aspcfg ^= CS53L30_ASP_SCLK_INV;
6078c2ecf20Sopenharmony_ci		break;
6088c2ecf20Sopenharmony_ci	default:
6098c2ecf20Sopenharmony_ci		break;
6108c2ecf20Sopenharmony_ci	}
6118c2ecf20Sopenharmony_ci
6128c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, CS53L30_ASPCFG_CTL,
6138c2ecf20Sopenharmony_ci			   CS53L30_ASP_MS | CS53L30_ASP_SCLK_INV, aspcfg);
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, CS53L30_ASP_CTL1,
6168c2ecf20Sopenharmony_ci			   CS53L30_ASP_TDM_PDN | CS53L30_SHIFT_LEFT, aspctl1);
6178c2ecf20Sopenharmony_ci
6188c2ecf20Sopenharmony_ci	return 0;
6198c2ecf20Sopenharmony_ci}
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_cistatic int cs53l30_pcm_hw_params(struct snd_pcm_substream *substream,
6228c2ecf20Sopenharmony_ci				 struct snd_pcm_hw_params *params,
6238c2ecf20Sopenharmony_ci				 struct snd_soc_dai *dai)
6248c2ecf20Sopenharmony_ci{
6258c2ecf20Sopenharmony_ci	struct cs53l30_private *priv = snd_soc_component_get_drvdata(dai->component);
6268c2ecf20Sopenharmony_ci	int srate = params_rate(params);
6278c2ecf20Sopenharmony_ci	int mclk_coeff;
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci	/* MCLK -> srate */
6308c2ecf20Sopenharmony_ci	mclk_coeff = cs53l30_get_mclk_coeff(priv->mclk_rate, srate);
6318c2ecf20Sopenharmony_ci	if (mclk_coeff < 0)
6328c2ecf20Sopenharmony_ci		return -EINVAL;
6338c2ecf20Sopenharmony_ci
6348c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, CS53L30_INT_SR_CTL,
6358c2ecf20Sopenharmony_ci			   CS53L30_INTRNL_FS_RATIO_MASK,
6368c2ecf20Sopenharmony_ci			   cs53l30_mclk_coeffs[mclk_coeff].internal_fs_ratio);
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, CS53L30_MCLKCTL,
6398c2ecf20Sopenharmony_ci			   CS53L30_MCLK_INT_SCALE_MASK,
6408c2ecf20Sopenharmony_ci			   cs53l30_mclk_coeffs[mclk_coeff].mclk_int_scale);
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci	regmap_update_bits(priv->regmap, CS53L30_ASPCFG_CTL,
6438c2ecf20Sopenharmony_ci			   CS53L30_ASP_RATE_MASK,
6448c2ecf20Sopenharmony_ci			   cs53l30_mclk_coeffs[mclk_coeff].asp_rate);
6458c2ecf20Sopenharmony_ci
6468c2ecf20Sopenharmony_ci	return 0;
6478c2ecf20Sopenharmony_ci}
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_cistatic int cs53l30_set_bias_level(struct snd_soc_component *component,
6508c2ecf20Sopenharmony_ci				  enum snd_soc_bias_level level)
6518c2ecf20Sopenharmony_ci{
6528c2ecf20Sopenharmony_ci	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
6538c2ecf20Sopenharmony_ci	struct cs53l30_private *priv = snd_soc_component_get_drvdata(component);
6548c2ecf20Sopenharmony_ci	unsigned int reg;
6558c2ecf20Sopenharmony_ci	int i, inter_max_check, ret;
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_ci	switch (level) {
6588c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_ON:
6598c2ecf20Sopenharmony_ci		break;
6608c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_PREPARE:
6618c2ecf20Sopenharmony_ci		if (dapm->bias_level == SND_SOC_BIAS_STANDBY)
6628c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, CS53L30_PWRCTL,
6638c2ecf20Sopenharmony_ci					   CS53L30_PDN_LP_MASK, 0);
6648c2ecf20Sopenharmony_ci		break;
6658c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_STANDBY:
6668c2ecf20Sopenharmony_ci		if (dapm->bias_level == SND_SOC_BIAS_OFF) {
6678c2ecf20Sopenharmony_ci			ret = clk_prepare_enable(priv->mclk);
6688c2ecf20Sopenharmony_ci			if (ret) {
6698c2ecf20Sopenharmony_ci				dev_err(component->dev,
6708c2ecf20Sopenharmony_ci					"failed to enable MCLK: %d\n", ret);
6718c2ecf20Sopenharmony_ci				return ret;
6728c2ecf20Sopenharmony_ci			}
6738c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, CS53L30_MCLKCTL,
6748c2ecf20Sopenharmony_ci					   CS53L30_MCLK_DIS_MASK, 0);
6758c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, CS53L30_PWRCTL,
6768c2ecf20Sopenharmony_ci					   CS53L30_PDN_ULP_MASK, 0);
6778c2ecf20Sopenharmony_ci			msleep(50);
6788c2ecf20Sopenharmony_ci		} else {
6798c2ecf20Sopenharmony_ci			regmap_update_bits(priv->regmap, CS53L30_PWRCTL,
6808c2ecf20Sopenharmony_ci					   CS53L30_PDN_ULP_MASK,
6818c2ecf20Sopenharmony_ci					   CS53L30_PDN_ULP);
6828c2ecf20Sopenharmony_ci		}
6838c2ecf20Sopenharmony_ci		break;
6848c2ecf20Sopenharmony_ci	case SND_SOC_BIAS_OFF:
6858c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, CS53L30_INT_MASK,
6868c2ecf20Sopenharmony_ci				   CS53L30_PDN_DONE, 0);
6878c2ecf20Sopenharmony_ci		/*
6888c2ecf20Sopenharmony_ci		 * If digital softramp is set, the amount of time required
6898c2ecf20Sopenharmony_ci		 * for power down increases and depends on the digital
6908c2ecf20Sopenharmony_ci		 * volume setting.
6918c2ecf20Sopenharmony_ci		 */
6928c2ecf20Sopenharmony_ci
6938c2ecf20Sopenharmony_ci		/* Set the max possible time if digsft is set */
6948c2ecf20Sopenharmony_ci		regmap_read(priv->regmap, CS53L30_SFT_RAMP, &reg);
6958c2ecf20Sopenharmony_ci		if (reg & CS53L30_DIGSFT_MASK)
6968c2ecf20Sopenharmony_ci			inter_max_check = CS53L30_PDN_POLL_MAX;
6978c2ecf20Sopenharmony_ci		else
6988c2ecf20Sopenharmony_ci			inter_max_check = 10;
6998c2ecf20Sopenharmony_ci
7008c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, CS53L30_PWRCTL,
7018c2ecf20Sopenharmony_ci				   CS53L30_PDN_ULP_MASK,
7028c2ecf20Sopenharmony_ci				   CS53L30_PDN_ULP);
7038c2ecf20Sopenharmony_ci		/* PDN_DONE will take a min of 20ms to be set.*/
7048c2ecf20Sopenharmony_ci		msleep(20);
7058c2ecf20Sopenharmony_ci		/* Clr status */
7068c2ecf20Sopenharmony_ci		regmap_read(priv->regmap, CS53L30_IS, &reg);
7078c2ecf20Sopenharmony_ci		for (i = 0; i < inter_max_check; i++) {
7088c2ecf20Sopenharmony_ci			if (inter_max_check < 10) {
7098c2ecf20Sopenharmony_ci				usleep_range(1000, 1100);
7108c2ecf20Sopenharmony_ci				regmap_read(priv->regmap, CS53L30_IS, &reg);
7118c2ecf20Sopenharmony_ci				if (reg & CS53L30_PDN_DONE)
7128c2ecf20Sopenharmony_ci					break;
7138c2ecf20Sopenharmony_ci			} else {
7148c2ecf20Sopenharmony_ci				usleep_range(10000, 10100);
7158c2ecf20Sopenharmony_ci				regmap_read(priv->regmap, CS53L30_IS, &reg);
7168c2ecf20Sopenharmony_ci				if (reg & CS53L30_PDN_DONE)
7178c2ecf20Sopenharmony_ci					break;
7188c2ecf20Sopenharmony_ci			}
7198c2ecf20Sopenharmony_ci		}
7208c2ecf20Sopenharmony_ci		/* PDN_DONE is set. We now can disable the MCLK */
7218c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, CS53L30_INT_MASK,
7228c2ecf20Sopenharmony_ci				   CS53L30_PDN_DONE, CS53L30_PDN_DONE);
7238c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, CS53L30_MCLKCTL,
7248c2ecf20Sopenharmony_ci				   CS53L30_MCLK_DIS_MASK,
7258c2ecf20Sopenharmony_ci				   CS53L30_MCLK_DIS);
7268c2ecf20Sopenharmony_ci		clk_disable_unprepare(priv->mclk);
7278c2ecf20Sopenharmony_ci		break;
7288c2ecf20Sopenharmony_ci	}
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_ci	return 0;
7318c2ecf20Sopenharmony_ci}
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_cistatic int cs53l30_set_tristate(struct snd_soc_dai *dai, int tristate)
7348c2ecf20Sopenharmony_ci{
7358c2ecf20Sopenharmony_ci	struct cs53l30_private *priv = snd_soc_component_get_drvdata(dai->component);
7368c2ecf20Sopenharmony_ci	u8 val = tristate ? CS53L30_ASP_3ST : 0;
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_ci	return regmap_update_bits(priv->regmap, CS53L30_ASP_CTL1,
7398c2ecf20Sopenharmony_ci				  CS53L30_ASP_3ST_MASK, val);
7408c2ecf20Sopenharmony_ci}
7418c2ecf20Sopenharmony_ci
7428c2ecf20Sopenharmony_cistatic unsigned int const cs53l30_src_rates[] = {
7438c2ecf20Sopenharmony_ci	8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000
7448c2ecf20Sopenharmony_ci};
7458c2ecf20Sopenharmony_ci
7468c2ecf20Sopenharmony_cistatic const struct snd_pcm_hw_constraint_list src_constraints = {
7478c2ecf20Sopenharmony_ci	.count = ARRAY_SIZE(cs53l30_src_rates),
7488c2ecf20Sopenharmony_ci	.list = cs53l30_src_rates,
7498c2ecf20Sopenharmony_ci};
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_cistatic int cs53l30_pcm_startup(struct snd_pcm_substream *substream,
7528c2ecf20Sopenharmony_ci			       struct snd_soc_dai *dai)
7538c2ecf20Sopenharmony_ci{
7548c2ecf20Sopenharmony_ci	snd_pcm_hw_constraint_list(substream->runtime, 0,
7558c2ecf20Sopenharmony_ci				   SNDRV_PCM_HW_PARAM_RATE, &src_constraints);
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci	return 0;
7588c2ecf20Sopenharmony_ci}
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_ci/*
7618c2ecf20Sopenharmony_ci * Note: CS53L30 counts the slot number per byte while ASoC counts the slot
7628c2ecf20Sopenharmony_ci * number per slot_width. So there is a difference between the slots of ASoC
7638c2ecf20Sopenharmony_ci * and the slots of CS53L30.
7648c2ecf20Sopenharmony_ci */
7658c2ecf20Sopenharmony_cistatic int cs53l30_set_dai_tdm_slot(struct snd_soc_dai *dai,
7668c2ecf20Sopenharmony_ci				    unsigned int tx_mask, unsigned int rx_mask,
7678c2ecf20Sopenharmony_ci				    int slots, int slot_width)
7688c2ecf20Sopenharmony_ci{
7698c2ecf20Sopenharmony_ci	struct cs53l30_private *priv = snd_soc_component_get_drvdata(dai->component);
7708c2ecf20Sopenharmony_ci	unsigned int loc[CS53L30_TDM_SLOT_MAX] = {48, 48, 48, 48};
7718c2ecf20Sopenharmony_ci	unsigned int slot_next, slot_step;
7728c2ecf20Sopenharmony_ci	u64 tx_enable = 0;
7738c2ecf20Sopenharmony_ci	int i;
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_ci	if (!rx_mask) {
7768c2ecf20Sopenharmony_ci		dev_err(dai->dev, "rx masks must not be 0\n");
7778c2ecf20Sopenharmony_ci		return -EINVAL;
7788c2ecf20Sopenharmony_ci	}
7798c2ecf20Sopenharmony_ci
7808c2ecf20Sopenharmony_ci	/* Assuming slot_width is not supposed to be greater than 64 */
7818c2ecf20Sopenharmony_ci	if (slots <= 0 || slot_width <= 0 || slot_width > 64) {
7828c2ecf20Sopenharmony_ci		dev_err(dai->dev, "invalid slot number or slot width\n");
7838c2ecf20Sopenharmony_ci		return -EINVAL;
7848c2ecf20Sopenharmony_ci	}
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_ci	if (slot_width & 0x7) {
7878c2ecf20Sopenharmony_ci		dev_err(dai->dev, "slot width must count in byte\n");
7888c2ecf20Sopenharmony_ci		return -EINVAL;
7898c2ecf20Sopenharmony_ci	}
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci	/* How many bytes in each ASoC slot */
7928c2ecf20Sopenharmony_ci	slot_step = slot_width >> 3;
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_ci	for (i = 0; rx_mask && i < CS53L30_TDM_SLOT_MAX; i++) {
7958c2ecf20Sopenharmony_ci		/* Find the first slot from LSB */
7968c2ecf20Sopenharmony_ci		slot_next = __ffs(rx_mask);
7978c2ecf20Sopenharmony_ci		/* Save the slot location by converting to CS53L30 slot */
7988c2ecf20Sopenharmony_ci		loc[i] = slot_next * slot_step;
7998c2ecf20Sopenharmony_ci		/* Create the mask of CS53L30 slot */
8008c2ecf20Sopenharmony_ci		tx_enable |= (u64)((u64)(1 << slot_step) - 1) << (u64)loc[i];
8018c2ecf20Sopenharmony_ci		/* Clear this slot from rx_mask */
8028c2ecf20Sopenharmony_ci		rx_mask &= ~(1 << slot_next);
8038c2ecf20Sopenharmony_ci	}
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	/* Error out to avoid slot shift */
8068c2ecf20Sopenharmony_ci	if (rx_mask && i == CS53L30_TDM_SLOT_MAX) {
8078c2ecf20Sopenharmony_ci		dev_err(dai->dev, "rx_mask exceeds max slot number: %d\n",
8088c2ecf20Sopenharmony_ci			CS53L30_TDM_SLOT_MAX);
8098c2ecf20Sopenharmony_ci		return -EINVAL;
8108c2ecf20Sopenharmony_ci	}
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_ci	/* Validate the last active CS53L30 slot */
8138c2ecf20Sopenharmony_ci	slot_next = loc[i - 1] + slot_step - 1;
8148c2ecf20Sopenharmony_ci	if (slot_next > 47) {
8158c2ecf20Sopenharmony_ci		dev_err(dai->dev, "slot selection out of bounds: %u\n",
8168c2ecf20Sopenharmony_ci			slot_next);
8178c2ecf20Sopenharmony_ci		return -EINVAL;
8188c2ecf20Sopenharmony_ci	}
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_ci	for (i = 0; i < CS53L30_TDM_SLOT_MAX && loc[i] != 48; i++) {
8218c2ecf20Sopenharmony_ci		regmap_update_bits(priv->regmap, CS53L30_ASP_TDMTX_CTL(i),
8228c2ecf20Sopenharmony_ci				   CS53L30_ASP_CHx_TX_LOC_MASK, loc[i]);
8238c2ecf20Sopenharmony_ci		dev_dbg(dai->dev, "loc[%d]=%x\n", i, loc[i]);
8248c2ecf20Sopenharmony_ci	}
8258c2ecf20Sopenharmony_ci
8268c2ecf20Sopenharmony_ci	for (i = 0; i < CS53L30_ASP_TDMTX_ENx_MAX && tx_enable; i++) {
8278c2ecf20Sopenharmony_ci		regmap_write(priv->regmap, CS53L30_ASP_TDMTX_ENx(i),
8288c2ecf20Sopenharmony_ci			     tx_enable & 0xff);
8298c2ecf20Sopenharmony_ci		tx_enable >>= 8;
8308c2ecf20Sopenharmony_ci		dev_dbg(dai->dev, "en_reg=%x, tx_enable=%llx\n",
8318c2ecf20Sopenharmony_ci			CS53L30_ASP_TDMTX_ENx(i), tx_enable & 0xff);
8328c2ecf20Sopenharmony_ci	}
8338c2ecf20Sopenharmony_ci
8348c2ecf20Sopenharmony_ci	return 0;
8358c2ecf20Sopenharmony_ci}
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_cistatic int cs53l30_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
8388c2ecf20Sopenharmony_ci{
8398c2ecf20Sopenharmony_ci	struct cs53l30_private *priv = snd_soc_component_get_drvdata(dai->component);
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci	gpiod_set_value_cansleep(priv->mute_gpio, mute);
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci	return 0;
8448c2ecf20Sopenharmony_ci}
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci/* SNDRV_PCM_RATE_KNOT -> 12000, 24000 Hz, limit with constraint list */
8478c2ecf20Sopenharmony_ci#define CS53L30_RATES (SNDRV_PCM_RATE_8000_48000 | SNDRV_PCM_RATE_KNOT)
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_ci#define CS53L30_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
8508c2ecf20Sopenharmony_ci			SNDRV_PCM_FMTBIT_S24_LE)
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_cistatic const struct snd_soc_dai_ops cs53l30_ops = {
8538c2ecf20Sopenharmony_ci	.startup = cs53l30_pcm_startup,
8548c2ecf20Sopenharmony_ci	.hw_params = cs53l30_pcm_hw_params,
8558c2ecf20Sopenharmony_ci	.set_fmt = cs53l30_set_dai_fmt,
8568c2ecf20Sopenharmony_ci	.set_sysclk = cs53l30_set_sysclk,
8578c2ecf20Sopenharmony_ci	.set_tristate = cs53l30_set_tristate,
8588c2ecf20Sopenharmony_ci	.set_tdm_slot = cs53l30_set_dai_tdm_slot,
8598c2ecf20Sopenharmony_ci	.mute_stream = cs53l30_mute_stream,
8608c2ecf20Sopenharmony_ci};
8618c2ecf20Sopenharmony_ci
8628c2ecf20Sopenharmony_cistatic struct snd_soc_dai_driver cs53l30_dai = {
8638c2ecf20Sopenharmony_ci	.name = "cs53l30",
8648c2ecf20Sopenharmony_ci	.capture = {
8658c2ecf20Sopenharmony_ci		.stream_name = "Capture",
8668c2ecf20Sopenharmony_ci		.channels_min = 1,
8678c2ecf20Sopenharmony_ci		.channels_max = 4,
8688c2ecf20Sopenharmony_ci		.rates = CS53L30_RATES,
8698c2ecf20Sopenharmony_ci		.formats = CS53L30_FORMATS,
8708c2ecf20Sopenharmony_ci	},
8718c2ecf20Sopenharmony_ci	.ops = &cs53l30_ops,
8728c2ecf20Sopenharmony_ci	.symmetric_rates = 1,
8738c2ecf20Sopenharmony_ci};
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_cistatic int cs53l30_component_probe(struct snd_soc_component *component)
8768c2ecf20Sopenharmony_ci{
8778c2ecf20Sopenharmony_ci	struct cs53l30_private *priv = snd_soc_component_get_drvdata(component);
8788c2ecf20Sopenharmony_ci	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
8798c2ecf20Sopenharmony_ci
8808c2ecf20Sopenharmony_ci	if (priv->use_sdout2)
8818c2ecf20Sopenharmony_ci		snd_soc_dapm_add_routes(dapm, cs53l30_dapm_routes_sdout2,
8828c2ecf20Sopenharmony_ci					ARRAY_SIZE(cs53l30_dapm_routes_sdout2));
8838c2ecf20Sopenharmony_ci	else
8848c2ecf20Sopenharmony_ci		snd_soc_dapm_add_routes(dapm, cs53l30_dapm_routes_sdout1,
8858c2ecf20Sopenharmony_ci					ARRAY_SIZE(cs53l30_dapm_routes_sdout1));
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_ci	return 0;
8888c2ecf20Sopenharmony_ci}
8898c2ecf20Sopenharmony_ci
8908c2ecf20Sopenharmony_cistatic const struct snd_soc_component_driver cs53l30_driver = {
8918c2ecf20Sopenharmony_ci	.probe			= cs53l30_component_probe,
8928c2ecf20Sopenharmony_ci	.set_bias_level		= cs53l30_set_bias_level,
8938c2ecf20Sopenharmony_ci	.controls		= cs53l30_snd_controls,
8948c2ecf20Sopenharmony_ci	.num_controls		= ARRAY_SIZE(cs53l30_snd_controls),
8958c2ecf20Sopenharmony_ci	.dapm_widgets		= cs53l30_dapm_widgets,
8968c2ecf20Sopenharmony_ci	.num_dapm_widgets	= ARRAY_SIZE(cs53l30_dapm_widgets),
8978c2ecf20Sopenharmony_ci	.dapm_routes		= cs53l30_dapm_routes,
8988c2ecf20Sopenharmony_ci	.num_dapm_routes	= ARRAY_SIZE(cs53l30_dapm_routes),
8998c2ecf20Sopenharmony_ci	.use_pmdown_time	= 1,
9008c2ecf20Sopenharmony_ci	.endianness		= 1,
9018c2ecf20Sopenharmony_ci	.non_legacy_dai_naming	= 1,
9028c2ecf20Sopenharmony_ci};
9038c2ecf20Sopenharmony_ci
9048c2ecf20Sopenharmony_cistatic struct regmap_config cs53l30_regmap = {
9058c2ecf20Sopenharmony_ci	.reg_bits = 8,
9068c2ecf20Sopenharmony_ci	.val_bits = 8,
9078c2ecf20Sopenharmony_ci
9088c2ecf20Sopenharmony_ci	.max_register = CS53L30_MAX_REGISTER,
9098c2ecf20Sopenharmony_ci	.reg_defaults = cs53l30_reg_defaults,
9108c2ecf20Sopenharmony_ci	.num_reg_defaults = ARRAY_SIZE(cs53l30_reg_defaults),
9118c2ecf20Sopenharmony_ci	.volatile_reg = cs53l30_volatile_register,
9128c2ecf20Sopenharmony_ci	.writeable_reg = cs53l30_writeable_register,
9138c2ecf20Sopenharmony_ci	.readable_reg = cs53l30_readable_register,
9148c2ecf20Sopenharmony_ci	.cache_type = REGCACHE_RBTREE,
9158c2ecf20Sopenharmony_ci};
9168c2ecf20Sopenharmony_ci
9178c2ecf20Sopenharmony_cistatic int cs53l30_i2c_probe(struct i2c_client *client,
9188c2ecf20Sopenharmony_ci			     const struct i2c_device_id *id)
9198c2ecf20Sopenharmony_ci{
9208c2ecf20Sopenharmony_ci	const struct device_node *np = client->dev.of_node;
9218c2ecf20Sopenharmony_ci	struct device *dev = &client->dev;
9228c2ecf20Sopenharmony_ci	struct cs53l30_private *cs53l30;
9238c2ecf20Sopenharmony_ci	unsigned int devid = 0;
9248c2ecf20Sopenharmony_ci	unsigned int reg;
9258c2ecf20Sopenharmony_ci	int ret = 0, i;
9268c2ecf20Sopenharmony_ci	u8 val;
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_ci	cs53l30 = devm_kzalloc(dev, sizeof(*cs53l30), GFP_KERNEL);
9298c2ecf20Sopenharmony_ci	if (!cs53l30)
9308c2ecf20Sopenharmony_ci		return -ENOMEM;
9318c2ecf20Sopenharmony_ci
9328c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(cs53l30->supplies); i++)
9338c2ecf20Sopenharmony_ci		cs53l30->supplies[i].supply = cs53l30_supply_names[i];
9348c2ecf20Sopenharmony_ci
9358c2ecf20Sopenharmony_ci	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(cs53l30->supplies),
9368c2ecf20Sopenharmony_ci				      cs53l30->supplies);
9378c2ecf20Sopenharmony_ci	if (ret) {
9388c2ecf20Sopenharmony_ci		dev_err(dev, "failed to get supplies: %d\n", ret);
9398c2ecf20Sopenharmony_ci		return ret;
9408c2ecf20Sopenharmony_ci	}
9418c2ecf20Sopenharmony_ci
9428c2ecf20Sopenharmony_ci	ret = regulator_bulk_enable(ARRAY_SIZE(cs53l30->supplies),
9438c2ecf20Sopenharmony_ci				    cs53l30->supplies);
9448c2ecf20Sopenharmony_ci	if (ret) {
9458c2ecf20Sopenharmony_ci		dev_err(dev, "failed to enable supplies: %d\n", ret);
9468c2ecf20Sopenharmony_ci		return ret;
9478c2ecf20Sopenharmony_ci	}
9488c2ecf20Sopenharmony_ci
9498c2ecf20Sopenharmony_ci	/* Reset the Device */
9508c2ecf20Sopenharmony_ci	cs53l30->reset_gpio = devm_gpiod_get_optional(dev, "reset",
9518c2ecf20Sopenharmony_ci						      GPIOD_OUT_LOW);
9528c2ecf20Sopenharmony_ci	if (IS_ERR(cs53l30->reset_gpio)) {
9538c2ecf20Sopenharmony_ci		ret = PTR_ERR(cs53l30->reset_gpio);
9548c2ecf20Sopenharmony_ci		goto error;
9558c2ecf20Sopenharmony_ci	}
9568c2ecf20Sopenharmony_ci
9578c2ecf20Sopenharmony_ci	gpiod_set_value_cansleep(cs53l30->reset_gpio, 1);
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_ci	i2c_set_clientdata(client, cs53l30);
9608c2ecf20Sopenharmony_ci
9618c2ecf20Sopenharmony_ci	cs53l30->mclk_rate = 0;
9628c2ecf20Sopenharmony_ci
9638c2ecf20Sopenharmony_ci	cs53l30->regmap = devm_regmap_init_i2c(client, &cs53l30_regmap);
9648c2ecf20Sopenharmony_ci	if (IS_ERR(cs53l30->regmap)) {
9658c2ecf20Sopenharmony_ci		ret = PTR_ERR(cs53l30->regmap);
9668c2ecf20Sopenharmony_ci		dev_err(dev, "regmap_init() failed: %d\n", ret);
9678c2ecf20Sopenharmony_ci		goto error;
9688c2ecf20Sopenharmony_ci	}
9698c2ecf20Sopenharmony_ci
9708c2ecf20Sopenharmony_ci	/* Initialize codec */
9718c2ecf20Sopenharmony_ci	ret = regmap_read(cs53l30->regmap, CS53L30_DEVID_AB, &reg);
9728c2ecf20Sopenharmony_ci	devid = reg << 12;
9738c2ecf20Sopenharmony_ci
9748c2ecf20Sopenharmony_ci	ret = regmap_read(cs53l30->regmap, CS53L30_DEVID_CD, &reg);
9758c2ecf20Sopenharmony_ci	devid |= reg << 4;
9768c2ecf20Sopenharmony_ci
9778c2ecf20Sopenharmony_ci	ret = regmap_read(cs53l30->regmap, CS53L30_DEVID_E, &reg);
9788c2ecf20Sopenharmony_ci	devid |= (reg & 0xF0) >> 4;
9798c2ecf20Sopenharmony_ci
9808c2ecf20Sopenharmony_ci	if (devid != CS53L30_DEVID) {
9818c2ecf20Sopenharmony_ci		ret = -ENODEV;
9828c2ecf20Sopenharmony_ci		dev_err(dev, "Device ID (%X). Expected %X\n",
9838c2ecf20Sopenharmony_ci			devid, CS53L30_DEVID);
9848c2ecf20Sopenharmony_ci		goto error;
9858c2ecf20Sopenharmony_ci	}
9868c2ecf20Sopenharmony_ci
9878c2ecf20Sopenharmony_ci	ret = regmap_read(cs53l30->regmap, CS53L30_REVID, &reg);
9888c2ecf20Sopenharmony_ci	if (ret < 0) {
9898c2ecf20Sopenharmony_ci		dev_err(dev, "failed to get Revision ID: %d\n", ret);
9908c2ecf20Sopenharmony_ci		goto error;
9918c2ecf20Sopenharmony_ci	}
9928c2ecf20Sopenharmony_ci
9938c2ecf20Sopenharmony_ci	/* Check if MCLK provided */
9948c2ecf20Sopenharmony_ci	cs53l30->mclk = devm_clk_get(dev, "mclk");
9958c2ecf20Sopenharmony_ci	if (IS_ERR(cs53l30->mclk)) {
9968c2ecf20Sopenharmony_ci		if (PTR_ERR(cs53l30->mclk) != -ENOENT) {
9978c2ecf20Sopenharmony_ci			ret = PTR_ERR(cs53l30->mclk);
9988c2ecf20Sopenharmony_ci			goto error;
9998c2ecf20Sopenharmony_ci		}
10008c2ecf20Sopenharmony_ci		/* Otherwise mark the mclk pointer to NULL */
10018c2ecf20Sopenharmony_ci		cs53l30->mclk = NULL;
10028c2ecf20Sopenharmony_ci	}
10038c2ecf20Sopenharmony_ci
10048c2ecf20Sopenharmony_ci	/* Fetch the MUTE control */
10058c2ecf20Sopenharmony_ci	cs53l30->mute_gpio = devm_gpiod_get_optional(dev, "mute",
10068c2ecf20Sopenharmony_ci						     GPIOD_OUT_HIGH);
10078c2ecf20Sopenharmony_ci	if (IS_ERR(cs53l30->mute_gpio)) {
10088c2ecf20Sopenharmony_ci		ret = PTR_ERR(cs53l30->mute_gpio);
10098c2ecf20Sopenharmony_ci		goto error;
10108c2ecf20Sopenharmony_ci	}
10118c2ecf20Sopenharmony_ci
10128c2ecf20Sopenharmony_ci	if (cs53l30->mute_gpio) {
10138c2ecf20Sopenharmony_ci		/* Enable MUTE controls via MUTE pin */
10148c2ecf20Sopenharmony_ci		regmap_write(cs53l30->regmap, CS53L30_MUTEP_CTL1,
10158c2ecf20Sopenharmony_ci			     CS53L30_MUTEP_CTL1_MUTEALL);
10168c2ecf20Sopenharmony_ci		/* Flip the polarity of MUTE pin */
10178c2ecf20Sopenharmony_ci		if (gpiod_is_active_low(cs53l30->mute_gpio))
10188c2ecf20Sopenharmony_ci			regmap_update_bits(cs53l30->regmap, CS53L30_MUTEP_CTL2,
10198c2ecf20Sopenharmony_ci					   CS53L30_MUTE_PIN_POLARITY, 0);
10208c2ecf20Sopenharmony_ci	}
10218c2ecf20Sopenharmony_ci
10228c2ecf20Sopenharmony_ci	if (!of_property_read_u8(np, "cirrus,micbias-lvl", &val))
10238c2ecf20Sopenharmony_ci		regmap_update_bits(cs53l30->regmap, CS53L30_MICBIAS_CTL,
10248c2ecf20Sopenharmony_ci				   CS53L30_MIC_BIAS_CTRL_MASK, val);
10258c2ecf20Sopenharmony_ci
10268c2ecf20Sopenharmony_ci	if (of_property_read_bool(np, "cirrus,use-sdout2"))
10278c2ecf20Sopenharmony_ci		cs53l30->use_sdout2 = true;
10288c2ecf20Sopenharmony_ci
10298c2ecf20Sopenharmony_ci	dev_info(dev, "Cirrus Logic CS53L30, Revision: %02X\n", reg & 0xFF);
10308c2ecf20Sopenharmony_ci
10318c2ecf20Sopenharmony_ci	ret = devm_snd_soc_register_component(dev, &cs53l30_driver, &cs53l30_dai, 1);
10328c2ecf20Sopenharmony_ci	if (ret) {
10338c2ecf20Sopenharmony_ci		dev_err(dev, "failed to register component: %d\n", ret);
10348c2ecf20Sopenharmony_ci		goto error;
10358c2ecf20Sopenharmony_ci	}
10368c2ecf20Sopenharmony_ci
10378c2ecf20Sopenharmony_ci	return 0;
10388c2ecf20Sopenharmony_ci
10398c2ecf20Sopenharmony_cierror:
10408c2ecf20Sopenharmony_ci	regulator_bulk_disable(ARRAY_SIZE(cs53l30->supplies),
10418c2ecf20Sopenharmony_ci			       cs53l30->supplies);
10428c2ecf20Sopenharmony_ci	return ret;
10438c2ecf20Sopenharmony_ci}
10448c2ecf20Sopenharmony_ci
10458c2ecf20Sopenharmony_cistatic int cs53l30_i2c_remove(struct i2c_client *client)
10468c2ecf20Sopenharmony_ci{
10478c2ecf20Sopenharmony_ci	struct cs53l30_private *cs53l30 = i2c_get_clientdata(client);
10488c2ecf20Sopenharmony_ci
10498c2ecf20Sopenharmony_ci	/* Hold down reset */
10508c2ecf20Sopenharmony_ci	gpiod_set_value_cansleep(cs53l30->reset_gpio, 0);
10518c2ecf20Sopenharmony_ci
10528c2ecf20Sopenharmony_ci	regulator_bulk_disable(ARRAY_SIZE(cs53l30->supplies),
10538c2ecf20Sopenharmony_ci			       cs53l30->supplies);
10548c2ecf20Sopenharmony_ci
10558c2ecf20Sopenharmony_ci	return 0;
10568c2ecf20Sopenharmony_ci}
10578c2ecf20Sopenharmony_ci
10588c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
10598c2ecf20Sopenharmony_cistatic int cs53l30_runtime_suspend(struct device *dev)
10608c2ecf20Sopenharmony_ci{
10618c2ecf20Sopenharmony_ci	struct cs53l30_private *cs53l30 = dev_get_drvdata(dev);
10628c2ecf20Sopenharmony_ci
10638c2ecf20Sopenharmony_ci	regcache_cache_only(cs53l30->regmap, true);
10648c2ecf20Sopenharmony_ci
10658c2ecf20Sopenharmony_ci	/* Hold down reset */
10668c2ecf20Sopenharmony_ci	gpiod_set_value_cansleep(cs53l30->reset_gpio, 0);
10678c2ecf20Sopenharmony_ci
10688c2ecf20Sopenharmony_ci	regulator_bulk_disable(ARRAY_SIZE(cs53l30->supplies),
10698c2ecf20Sopenharmony_ci			       cs53l30->supplies);
10708c2ecf20Sopenharmony_ci
10718c2ecf20Sopenharmony_ci	return 0;
10728c2ecf20Sopenharmony_ci}
10738c2ecf20Sopenharmony_ci
10748c2ecf20Sopenharmony_cistatic int cs53l30_runtime_resume(struct device *dev)
10758c2ecf20Sopenharmony_ci{
10768c2ecf20Sopenharmony_ci	struct cs53l30_private *cs53l30 = dev_get_drvdata(dev);
10778c2ecf20Sopenharmony_ci	int ret;
10788c2ecf20Sopenharmony_ci
10798c2ecf20Sopenharmony_ci	ret = regulator_bulk_enable(ARRAY_SIZE(cs53l30->supplies),
10808c2ecf20Sopenharmony_ci				    cs53l30->supplies);
10818c2ecf20Sopenharmony_ci	if (ret) {
10828c2ecf20Sopenharmony_ci		dev_err(dev, "failed to enable supplies: %d\n", ret);
10838c2ecf20Sopenharmony_ci		return ret;
10848c2ecf20Sopenharmony_ci	}
10858c2ecf20Sopenharmony_ci
10868c2ecf20Sopenharmony_ci	gpiod_set_value_cansleep(cs53l30->reset_gpio, 1);
10878c2ecf20Sopenharmony_ci
10888c2ecf20Sopenharmony_ci	regcache_cache_only(cs53l30->regmap, false);
10898c2ecf20Sopenharmony_ci	ret = regcache_sync(cs53l30->regmap);
10908c2ecf20Sopenharmony_ci	if (ret) {
10918c2ecf20Sopenharmony_ci		dev_err(dev, "failed to synchronize regcache: %d\n", ret);
10928c2ecf20Sopenharmony_ci		return ret;
10938c2ecf20Sopenharmony_ci	}
10948c2ecf20Sopenharmony_ci
10958c2ecf20Sopenharmony_ci	return 0;
10968c2ecf20Sopenharmony_ci}
10978c2ecf20Sopenharmony_ci#endif
10988c2ecf20Sopenharmony_ci
10998c2ecf20Sopenharmony_cistatic const struct dev_pm_ops cs53l30_runtime_pm = {
11008c2ecf20Sopenharmony_ci	SET_RUNTIME_PM_OPS(cs53l30_runtime_suspend, cs53l30_runtime_resume,
11018c2ecf20Sopenharmony_ci			   NULL)
11028c2ecf20Sopenharmony_ci};
11038c2ecf20Sopenharmony_ci
11048c2ecf20Sopenharmony_cistatic const struct of_device_id cs53l30_of_match[] = {
11058c2ecf20Sopenharmony_ci	{ .compatible = "cirrus,cs53l30", },
11068c2ecf20Sopenharmony_ci	{},
11078c2ecf20Sopenharmony_ci};
11088c2ecf20Sopenharmony_ci
11098c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, cs53l30_of_match);
11108c2ecf20Sopenharmony_ci
11118c2ecf20Sopenharmony_cistatic const struct i2c_device_id cs53l30_id[] = {
11128c2ecf20Sopenharmony_ci	{ "cs53l30", 0 },
11138c2ecf20Sopenharmony_ci	{}
11148c2ecf20Sopenharmony_ci};
11158c2ecf20Sopenharmony_ci
11168c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, cs53l30_id);
11178c2ecf20Sopenharmony_ci
11188c2ecf20Sopenharmony_cistatic struct i2c_driver cs53l30_i2c_driver = {
11198c2ecf20Sopenharmony_ci	.driver = {
11208c2ecf20Sopenharmony_ci		.name = "cs53l30",
11218c2ecf20Sopenharmony_ci		.of_match_table = cs53l30_of_match,
11228c2ecf20Sopenharmony_ci		.pm = &cs53l30_runtime_pm,
11238c2ecf20Sopenharmony_ci	},
11248c2ecf20Sopenharmony_ci	.id_table = cs53l30_id,
11258c2ecf20Sopenharmony_ci	.probe = cs53l30_i2c_probe,
11268c2ecf20Sopenharmony_ci	.remove = cs53l30_i2c_remove,
11278c2ecf20Sopenharmony_ci};
11288c2ecf20Sopenharmony_ci
11298c2ecf20Sopenharmony_cimodule_i2c_driver(cs53l30_i2c_driver);
11308c2ecf20Sopenharmony_ci
11318c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("ASoC CS53L30 driver");
11328c2ecf20Sopenharmony_ciMODULE_AUTHOR("Paul Handrigan, Cirrus Logic Inc, <Paul.Handrigan@cirrus.com>");
11338c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
1134