linux/sound/soc/codecs/rt5682s.c

// SPDX-License-Identifier: GPL-2.0-only
//
// rt5682s.c  --  RT5682I-VS ALSA SoC audio component driver
//
// Copyright 2021 Realtek Semiconductor Corp.
// Author: Derek Fang <[email protected]>
//

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/i2c.h>
#include <linux/platform_device.h>
#include <linux/spi/spi.h>
#include <linux/acpi.h>
#include <linux/gpio/consumer.h>
#include <linux/mutex.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/jack.h>
#include <sound/soc.h>
#include <sound/soc-dapm.h>
#include <sound/initval.h>
#include <sound/tlv.h>
#include <sound/rt5682s.h>

#include "rt5682s.h"

#define DEVICE_ID

static const struct rt5682s_platform_data i2s_default_platform_data =;

static const char *rt5682s_supply_names[RT5682S_NUM_SUPPLIES] =;

static const struct reg_sequence patch_list[] =;

static void rt5682s_apply_patch_list(struct rt5682s_priv *rt5682s,
		struct device *dev)
{}

static const struct reg_default rt5682s_reg[] =;

static bool rt5682s_volatile_register(struct device *dev, unsigned int reg)
{}

static bool rt5682s_readable_register(struct device *dev, unsigned int reg)
{}

static void rt5682s_reset(struct rt5682s_priv *rt5682s)
{}

static int rt5682s_button_detect(struct snd_soc_component *component)
{}

enum {};

static void rt5682s_sar_power_mode(struct snd_soc_component *component, int mode)
{}

static void rt5682s_enable_push_button_irq(struct snd_soc_component *component)
{}

static void rt5682s_disable_push_button_irq(struct snd_soc_component *component)
{}

/**
 * rt5682s_headset_detect - Detect headset.
 * @component: SoC audio component device.
 * @jack_insert: Jack insert or not.
 *
 * Detect whether is headset or not when jack inserted.
 *
 * Returns detect status.
 */
static int rt5682s_headset_detect(struct snd_soc_component *component, int jack_insert)
{}

static void rt5682s_jack_detect_handler(struct work_struct *work)
{}

static void rt5682s_jd_check_handler(struct work_struct *work)
{}

static irqreturn_t rt5682s_irq(int irq, void *data)
{}

static int rt5682s_set_jack_detect(struct snd_soc_component *component,
		struct snd_soc_jack *hs_jack, void *data)
{}

static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -9562, 75, 0);
static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0);
static const DECLARE_TLV_DB_SCALE(cbj_bst_tlv, -1200, 150, 0);

static const struct snd_kcontrol_new rt5682s_snd_controls[] =;

/**
 * rt5682s_sel_asrc_clk_src - select ASRC clock source for a set of filters
 * @component: SoC audio component device.
 * @filter_mask: mask of filters.
 * @clk_src: clock source
 *
 * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5682S can
 * only support standard 32fs or 64fs i2s format, ASRC should be enabled to
 * support special i2s clock format such as Intel's 100fs(100 * sampling rate).
 * ASRC function will track i2s clock and generate a corresponding system clock
 * for codec. This function provides an API to select the clock source for a
 * set of filters specified by the mask. And the component driver will turn on
 * ASRC for these filters if ASRC is selected as their clock source.
 */
int rt5682s_sel_asrc_clk_src(struct snd_soc_component *component,
		unsigned int filter_mask, unsigned int clk_src)
{}
EXPORT_SYMBOL_GPL();

static int rt5682s_div_sel(struct rt5682s_priv *rt5682s,
		int target, const int div[], int size)
{}

static int get_clk_info(int sclk, int rate)
{}

/**
 * set_dmic_clk - Set parameter of dmic.
 *
 * @w: DAPM widget.
 * @kcontrol: The kcontrol of this widget.
 * @event: Event id.
 *
 * Choose dmic clock between 1MHz and 3MHz.
 * It is better for clock to approximate 3MHz.
 */
static int set_dmic_clk(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{}


static int rt5682s_set_pllb_power(struct rt5682s_priv *rt5682s, int on)
{}

static int set_pllb_event(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{}

static void rt5682s_set_filter_clk(struct rt5682s_priv *rt5682s, int reg, int ref)
{}

static int set_filter_clk(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{}

static int set_dmic_power(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{}

static void rt5682s_set_i2s(struct rt5682s_priv *rt5682s, int id, int on)
{}

static int set_i2s_event(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{}

static int is_sys_clk_from_plla(struct snd_soc_dapm_widget *w,
		struct snd_soc_dapm_widget *sink)
{}

static int is_sys_clk_from_pllb(struct snd_soc_dapm_widget *w,
		struct snd_soc_dapm_widget *sink)
{}

static int is_using_asrc(struct snd_soc_dapm_widget *w,
		struct snd_soc_dapm_widget *sink)
{}

static int rt5682s_hp_amp_event(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{}

static int rt5682s_stereo1_adc_mixl_event(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{}

static int sar_power_event(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{}

/* Interface data select */
static const char * const rt5682s_data_select[] =;

static SOC_ENUM_SINGLE_DECL(rt5682s_if2_adc_enum, RT5682S_DIG_INF2_DATA,
	RT5682S_IF2_ADC_SEL_SFT, rt5682s_data_select);

static SOC_ENUM_SINGLE_DECL(rt5682s_if1_01_adc_enum, RT5682S_TDM_ADDA_CTRL_1,
	RT5682S_IF1_ADC1_SEL_SFT, rt5682s_data_select);

static SOC_ENUM_SINGLE_DECL(rt5682s_if1_23_adc_enum, RT5682S_TDM_ADDA_CTRL_1,
	RT5682S_IF1_ADC2_SEL_SFT, rt5682s_data_select);

static SOC_ENUM_SINGLE_DECL(rt5682s_if1_45_adc_enum, RT5682S_TDM_ADDA_CTRL_1,
	RT5682S_IF1_ADC3_SEL_SFT, rt5682s_data_select);

static SOC_ENUM_SINGLE_DECL(rt5682s_if1_67_adc_enum, RT5682S_TDM_ADDA_CTRL_1,
	RT5682S_IF1_ADC4_SEL_SFT, rt5682s_data_select);

static const struct snd_kcontrol_new rt5682s_if2_adc_swap_mux =;

static const struct snd_kcontrol_new rt5682s_if1_01_adc_swap_mux =;

static const struct snd_kcontrol_new rt5682s_if1_23_adc_swap_mux =;

static const struct snd_kcontrol_new rt5682s_if1_45_adc_swap_mux =;

static const struct snd_kcontrol_new rt5682s_if1_67_adc_swap_mux =;

/* Digital Mixer */
static const struct snd_kcontrol_new rt5682s_sto1_adc_l_mix[] =;

static const struct snd_kcontrol_new rt5682s_sto1_adc_r_mix[] =;

static const struct snd_kcontrol_new rt5682s_dac_l_mix[] =;

static const struct snd_kcontrol_new rt5682s_dac_r_mix[] =;

static const struct snd_kcontrol_new rt5682s_sto1_dac_l_mix[] =;

static const struct snd_kcontrol_new rt5682s_sto1_dac_r_mix[] =;

/* Analog Input Mixer */
static const struct snd_kcontrol_new rt5682s_rec1_l_mix[] =;

static const struct snd_kcontrol_new rt5682s_rec1_r_mix[] =;

/* STO1 ADC1 Source */
/* MX-26 [13] [5] */
static const char * const rt5682s_sto1_adc1_src[] =;

static SOC_ENUM_SINGLE_DECL(rt5682s_sto1_adc1l_enum, RT5682S_STO1_ADC_MIXER,
	RT5682S_STO1_ADC1L_SRC_SFT, rt5682s_sto1_adc1_src);

static const struct snd_kcontrol_new rt5682s_sto1_adc1l_mux =;

static SOC_ENUM_SINGLE_DECL(rt5682s_sto1_adc1r_enum, RT5682S_STO1_ADC_MIXER,
	RT5682S_STO1_ADC1R_SRC_SFT, rt5682s_sto1_adc1_src);

static const struct snd_kcontrol_new rt5682s_sto1_adc1r_mux =;

/* STO1 ADC Source */
/* MX-26 [11:10] [3:2] */
static const char * const rt5682s_sto1_adc_src[] =;

static SOC_ENUM_SINGLE_DECL(rt5682s_sto1_adcl_enum, RT5682S_STO1_ADC_MIXER,
	RT5682S_STO1_ADCL_SRC_SFT, rt5682s_sto1_adc_src);

static const struct snd_kcontrol_new rt5682s_sto1_adcl_mux =;

static SOC_ENUM_SINGLE_DECL(rt5682s_sto1_adcr_enum, RT5682S_STO1_ADC_MIXER,
	RT5682S_STO1_ADCR_SRC_SFT, rt5682s_sto1_adc_src);

static const struct snd_kcontrol_new rt5682s_sto1_adcr_mux =;

/* STO1 ADC2 Source */
/* MX-26 [12] [4] */
static const char * const rt5682s_sto1_adc2_src[] =;

static SOC_ENUM_SINGLE_DECL(rt5682s_sto1_adc2l_enum, RT5682S_STO1_ADC_MIXER,
	RT5682S_STO1_ADC2L_SRC_SFT, rt5682s_sto1_adc2_src);

static const struct snd_kcontrol_new rt5682s_sto1_adc2l_mux =;

static SOC_ENUM_SINGLE_DECL(rt5682s_sto1_adc2r_enum, RT5682S_STO1_ADC_MIXER,
	RT5682S_STO1_ADC2R_SRC_SFT, rt5682s_sto1_adc2_src);

static const struct snd_kcontrol_new rt5682s_sto1_adc2r_mux =;

/* MX-79 [6:4] I2S1 ADC data location */
static const unsigned int rt5682s_if1_adc_slot_values[] =;

static const char * const rt5682s_if1_adc_slot_src[] =;

static SOC_VALUE_ENUM_SINGLE_DECL(rt5682s_if1_adc_slot_enum,
	RT5682S_TDM_CTRL, RT5682S_TDM_ADC_LCA_SFT, RT5682S_TDM_ADC_LCA_MASK,
	rt5682s_if1_adc_slot_src, rt5682s_if1_adc_slot_values);

static const struct snd_kcontrol_new rt5682s_if1_adc_slot_mux =;

/* Analog DAC L1 Source, Analog DAC R1 Source*/
/* MX-2B [4], MX-2B [0]*/
static const char * const rt5682s_alg_dac1_src[] =;

static SOC_ENUM_SINGLE_DECL(rt5682s_alg_dac_l1_enum, RT5682S_A_DAC1_MUX,
	RT5682S_A_DACL1_SFT, rt5682s_alg_dac1_src);

static const struct snd_kcontrol_new rt5682s_alg_dac_l1_mux =;

static SOC_ENUM_SINGLE_DECL(rt5682s_alg_dac_r1_enum, RT5682S_A_DAC1_MUX,
	RT5682S_A_DACR1_SFT, rt5682s_alg_dac1_src);

static const struct snd_kcontrol_new rt5682s_alg_dac_r1_mux =;

static const unsigned int rt5682s_adcdat_pin_values[] =;

static const char * const rt5682s_adcdat_pin_select[] =;

static SOC_VALUE_ENUM_SINGLE_DECL(rt5682s_adcdat_pin_enum,
	RT5682S_GPIO_CTRL_1, RT5682S_GP4_PIN_SFT, RT5682S_GP4_PIN_MASK,
	rt5682s_adcdat_pin_select, rt5682s_adcdat_pin_values);

static const struct snd_kcontrol_new rt5682s_adcdat_pin_ctrl =;

static const struct snd_soc_dapm_widget rt5682s_dapm_widgets[] =;

static const struct snd_soc_dapm_route rt5682s_dapm_routes[] =;

static int rt5682s_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
		unsigned int rx_mask, int slots, int slot_width)
{}

static int rt5682s_hw_params(struct snd_pcm_substream *substream,
		struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
{}

static int rt5682s_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
{}

static int rt5682s_set_component_sysclk(struct snd_soc_component *component,
		int clk_id, int source, unsigned int freq, int dir)
{}

static const struct pll_calc_map plla_table[] =;

static const struct pll_calc_map pllb_table[] =;

static int find_pll_inter_combination(unsigned int f_in, unsigned int f_out,
		struct pll_calc_map *a, struct pll_calc_map *b)
{}

static int rt5682s_set_component_pll(struct snd_soc_component *component,
		int pll_id, int source, unsigned int freq_in,
		unsigned int freq_out)
{}

static int rt5682s_set_bclk1_ratio(struct snd_soc_dai *dai,
		unsigned int ratio)
{}

static int rt5682s_set_bclk2_ratio(struct snd_soc_dai *dai, unsigned int ratio)
{}

static int rt5682s_set_bias_level(struct snd_soc_component *component,
		enum snd_soc_bias_level level)
{}

#ifdef CONFIG_COMMON_CLK
#define CLK_PLL2_FIN
#define CLK_48
#define CLK_44

static bool rt5682s_clk_check(struct rt5682s_priv *rt5682s)
{}

static int rt5682s_wclk_prepare(struct clk_hw *hw)
{}

static void rt5682s_wclk_unprepare(struct clk_hw *hw)
{}

static unsigned long rt5682s_wclk_recalc_rate(struct clk_hw *hw,
					     unsigned long parent_rate)
{}

static long rt5682s_wclk_round_rate(struct clk_hw *hw, unsigned long rate,
				   unsigned long *parent_rate)
{}

static int rt5682s_wclk_set_rate(struct clk_hw *hw, unsigned long rate,
				unsigned long parent_rate)
{}

static unsigned long rt5682s_bclk_recalc_rate(struct clk_hw *hw,
					     unsigned long parent_rate)
{}

static unsigned long rt5682s_bclk_get_factor(unsigned long rate,
					    unsigned long parent_rate)
{}

static long rt5682s_bclk_round_rate(struct clk_hw *hw, unsigned long rate,
				   unsigned long *parent_rate)
{}

static int rt5682s_bclk_set_rate(struct clk_hw *hw, unsigned long rate,
				unsigned long parent_rate)
{}

static const struct clk_ops rt5682s_dai_clk_ops[RT5682S_DAI_NUM_CLKS] =;

static int rt5682s_register_dai_clks(struct snd_soc_component *component)
{}

static int rt5682s_dai_probe_clks(struct snd_soc_component *component)
{}
#else
static inline int rt5682s_dai_probe_clks(struct snd_soc_component *component)
{
	return 0;
}
#endif /* CONFIG_COMMON_CLK */

static int rt5682s_probe(struct snd_soc_component *component)
{}

static void rt5682s_remove(struct snd_soc_component *component)
{}

#ifdef CONFIG_PM
static int rt5682s_suspend(struct snd_soc_component *component)
{}

static int rt5682s_resume(struct snd_soc_component *component)
{}
#else
#define rt5682s_suspend
#define rt5682s_resume
#endif

static const struct snd_soc_dai_ops rt5682s_aif1_dai_ops =;

static const struct snd_soc_dai_ops rt5682s_aif2_dai_ops =;

static const struct snd_soc_component_driver rt5682s_soc_component_dev =;

static int rt5682s_parse_dt(struct rt5682s_priv *rt5682s, struct device *dev)
{}

static void rt5682s_calibrate(struct rt5682s_priv *rt5682s)
{}

static const struct regmap_config rt5682s_regmap =;

static struct snd_soc_dai_driver rt5682s_dai[] =;

static void rt5682s_i2c_disable_regulators(void *data)
{}

static int rt5682s_i2c_probe(struct i2c_client *i2c)
{}

static void rt5682s_i2c_shutdown(struct i2c_client *client)
{}

static void rt5682s_i2c_remove(struct i2c_client *client)
{}

static const struct of_device_id rt5682s_of_match[] =;
MODULE_DEVICE_TABLE(of, rt5682s_of_match);

static const struct acpi_device_id rt5682s_acpi_match[] =;
MODULE_DEVICE_TABLE(acpi, rt5682s_acpi_match);

static const struct i2c_device_id rt5682s_i2c_id[] =;
MODULE_DEVICE_TABLE(i2c, rt5682s_i2c_id);

static struct i2c_driver rt5682s_i2c_driver =;
module_i2c_driver();

MODULE_DESCRIPTION();
MODULE_AUTHOR();
MODULE_LICENSE();