linux/sound/soc/codecs/rt5682.c

// SPDX-License-Identifier: GPL-2.0-only
//
// rt5682.c  --  RT5682 ALSA SoC audio component driver
//
// Copyright 2018 Realtek Semiconductor Corp.
// Author: Bard Liao <[email protected]>
//

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/pm_runtime.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/rt5682.h>

#include "rl6231.h"
#include "rt5682.h"

const char *rt5682_supply_names[RT5682_NUM_SUPPLIES] =;
EXPORT_SYMBOL_GPL();

static const struct reg_sequence patch_list[] =;

void rt5682_apply_patch_list(struct rt5682_priv *rt5682, struct device *dev)
{}
EXPORT_SYMBOL_GPL();

const struct reg_default rt5682_reg[RT5682_REG_NUM] =;
EXPORT_SYMBOL_GPL();

bool rt5682_volatile_register(struct device *dev, unsigned int reg)
{}
EXPORT_SYMBOL_GPL();

bool rt5682_readable_register(struct device *dev, unsigned int reg)
{}
EXPORT_SYMBOL_GPL();

static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 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);

/* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
static const DECLARE_TLV_DB_RANGE(bst_tlv,
	0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
	1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
	2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
	3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
	6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
	7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
	8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
);

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

static SOC_ENUM_SINGLE_DECL(rt5682_if2_adc_enum,
	RT5682_DIG_INF2_DATA, RT5682_IF2_ADC_SEL_SFT, rt5682_data_select);

static SOC_ENUM_SINGLE_DECL(rt5682_if1_01_adc_enum,
	RT5682_TDM_ADDA_CTRL_1, RT5682_IF1_ADC1_SEL_SFT, rt5682_data_select);

static SOC_ENUM_SINGLE_DECL(rt5682_if1_23_adc_enum,
	RT5682_TDM_ADDA_CTRL_1, RT5682_IF1_ADC2_SEL_SFT, rt5682_data_select);

static SOC_ENUM_SINGLE_DECL(rt5682_if1_45_adc_enum,
	RT5682_TDM_ADDA_CTRL_1, RT5682_IF1_ADC3_SEL_SFT, rt5682_data_select);

static SOC_ENUM_SINGLE_DECL(rt5682_if1_67_adc_enum,
	RT5682_TDM_ADDA_CTRL_1, RT5682_IF1_ADC4_SEL_SFT, rt5682_data_select);

static const struct snd_kcontrol_new rt5682_if2_adc_swap_mux =;

static const struct snd_kcontrol_new rt5682_if1_01_adc_swap_mux =;

static const struct snd_kcontrol_new rt5682_if1_23_adc_swap_mux =;

static const struct snd_kcontrol_new rt5682_if1_45_adc_swap_mux =;

static const struct snd_kcontrol_new rt5682_if1_67_adc_swap_mux =;

static const char * const rt5682_dac_select[] =;

static SOC_ENUM_SINGLE_DECL(rt5682_dacl_enum,
	RT5682_AD_DA_MIXER, RT5682_DAC1_L_SEL_SFT, rt5682_dac_select);

static const struct snd_kcontrol_new rt5682_dac_l_mux =;

static SOC_ENUM_SINGLE_DECL(rt5682_dacr_enum,
	RT5682_AD_DA_MIXER, RT5682_DAC1_R_SEL_SFT, rt5682_dac_select);

static const struct snd_kcontrol_new rt5682_dac_r_mux =;

void rt5682_reset(struct rt5682_priv *rt5682)
{}
EXPORT_SYMBOL_GPL();

/**
 * rt5682_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 RT5682 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 rt5682_sel_asrc_clk_src(struct snd_soc_component *component,
		unsigned int filter_mask, unsigned int clk_src)
{}
EXPORT_SYMBOL_GPL();

static int rt5682_button_detect(struct snd_soc_component *component)
{}

static void rt5682_enable_push_button_irq(struct snd_soc_component *component,
		bool enable)
{}

/**
 * rt5682_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 rt5682_headset_detect(struct snd_soc_component *component, int jack_insert)
{}

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

void rt5682_jack_detect_handler(struct work_struct *work)
{}
EXPORT_SYMBOL_GPL();

static const struct snd_kcontrol_new rt5682_snd_controls[] =;

static int rt5682_div_sel(struct rt5682_priv *rt5682,
		int target, const int div[], int size)
{}

/**
 * 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 set_filter_clk(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{}

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

static int is_sys_clk_from_pll2(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)
{}

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

static const struct snd_kcontrol_new rt5682_sto1_adc_r_mix[] =;

static const struct snd_kcontrol_new rt5682_dac_l_mix[] =;

static const struct snd_kcontrol_new rt5682_dac_r_mix[] =;

static const struct snd_kcontrol_new rt5682_sto1_dac_l_mix[] =;

static const struct snd_kcontrol_new rt5682_sto1_dac_r_mix[] =;

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

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

static SOC_ENUM_SINGLE_DECL(
	rt5682_sto1_adc1l_enum, RT5682_STO1_ADC_MIXER,
	RT5682_STO1_ADC1L_SRC_SFT, rt5682_sto1_adc1_src);

static const struct snd_kcontrol_new rt5682_sto1_adc1l_mux =;

static SOC_ENUM_SINGLE_DECL(
	rt5682_sto1_adc1r_enum, RT5682_STO1_ADC_MIXER,
	RT5682_STO1_ADC1R_SRC_SFT, rt5682_sto1_adc1_src);

static const struct snd_kcontrol_new rt5682_sto1_adc1r_mux =;

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

static SOC_ENUM_SINGLE_DECL(
	rt5682_sto1_adcl_enum, RT5682_STO1_ADC_MIXER,
	RT5682_STO1_ADCL_SRC_SFT, rt5682_sto1_adc_src);

static const struct snd_kcontrol_new rt5682_sto1_adcl_mux =;

static SOC_ENUM_SINGLE_DECL(
	rt5682_sto1_adcr_enum, RT5682_STO1_ADC_MIXER,
	RT5682_STO1_ADCR_SRC_SFT, rt5682_sto1_adc_src);

static const struct snd_kcontrol_new rt5682_sto1_adcr_mux =;

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

static SOC_ENUM_SINGLE_DECL(
	rt5682_sto1_adc2l_enum, RT5682_STO1_ADC_MIXER,
	RT5682_STO1_ADC2L_SRC_SFT, rt5682_sto1_adc2_src);

static const struct snd_kcontrol_new rt5682_sto1_adc2l_mux =;

static SOC_ENUM_SINGLE_DECL(
	rt5682_sto1_adc2r_enum, RT5682_STO1_ADC_MIXER,
	RT5682_STO1_ADC2R_SRC_SFT, rt5682_sto1_adc2_src);

static const struct snd_kcontrol_new rt5682_sto1_adc2r_mux =;

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

static const char * const rt5682_if1_adc_slot_src[] =;

static SOC_VALUE_ENUM_SINGLE_DECL(rt5682_if1_adc_slot_enum,
	RT5682_TDM_CTRL, RT5682_TDM_ADC_LCA_SFT, RT5682_TDM_ADC_LCA_MASK,
	rt5682_if1_adc_slot_src, rt5682_if1_adc_slot_values);

static const struct snd_kcontrol_new rt5682_if1_adc_slot_mux =;

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

static SOC_ENUM_SINGLE_DECL(
	rt5682_alg_dac_l1_enum, RT5682_A_DAC1_MUX,
	RT5682_A_DACL1_SFT, rt5682_alg_dac1_src);

static const struct snd_kcontrol_new rt5682_alg_dac_l1_mux =;

static SOC_ENUM_SINGLE_DECL(
	rt5682_alg_dac_r1_enum, RT5682_A_DAC1_MUX,
	RT5682_A_DACR1_SFT, rt5682_alg_dac1_src);

static const struct snd_kcontrol_new rt5682_alg_dac_r1_mux =;

/* Out Switch */
static const struct snd_kcontrol_new hpol_switch =;
static const struct snd_kcontrol_new hpor_switch =;

static int rt5682_hp_event(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 int rt5682_set_verf(struct snd_soc_dapm_widget *w,
		struct snd_kcontrol *kcontrol, int event)
{}

static const unsigned int rt5682_adcdat_pin_values[] =;

static const char * const rt5682_adcdat_pin_select[] =;

static SOC_VALUE_ENUM_SINGLE_DECL(rt5682_adcdat_pin_enum,
	RT5682_GPIO_CTRL_1, RT5682_GP4_PIN_SFT, RT5682_GP4_PIN_MASK,
	rt5682_adcdat_pin_select, rt5682_adcdat_pin_values);

static const struct snd_kcontrol_new rt5682_adcdat_pin_ctrl =;

static const unsigned int rt5682_hpo_sig_out_values[] =;

static const char * const rt5682_hpo_sig_out_mode[] =;

static SOC_VALUE_ENUM_SINGLE_DECL(rt5682_hpo_sig_out_enum,
	RT5682_HP_LOGIC_CTRL_2, 0, RT5682_HP_LC2_SIG_SOUR1_MASK,
	rt5682_hpo_sig_out_mode, rt5682_hpo_sig_out_values);

static const struct snd_kcontrol_new rt5682_hpo_sig_demux =;

static const struct snd_soc_dapm_widget rt5682_dapm_widgets[] =;

static const struct snd_soc_dapm_route rt5682_dapm_routes[] =;

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

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

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

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

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

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

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

static int rt5682_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 rt5682_clk_check(struct rt5682_priv *rt5682)
{}

static int rt5682_wclk_prepare(struct clk_hw *hw)
{}

static void rt5682_wclk_unprepare(struct clk_hw *hw)
{}

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

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

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

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

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

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

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

static const struct clk_ops rt5682_dai_clk_ops[RT5682_DAI_NUM_CLKS] =;

int rt5682_register_dai_clks(struct rt5682_priv *rt5682)
{}
EXPORT_SYMBOL_GPL();
#endif /* CONFIG_COMMON_CLK */

static int rt5682_probe(struct snd_soc_component *component)
{}

static void rt5682_remove(struct snd_soc_component *component)
{}

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

static int rt5682_resume(struct snd_soc_component *component)
{}
#else
#define rt5682_suspend
#define rt5682_resume
#endif

const struct snd_soc_dai_ops rt5682_aif1_dai_ops =;
EXPORT_SYMBOL_GPL();

const struct snd_soc_dai_ops rt5682_aif2_dai_ops =;
EXPORT_SYMBOL_GPL();

const struct snd_soc_component_driver rt5682_soc_component_dev =;
EXPORT_SYMBOL_GPL();

int rt5682_parse_dt(struct rt5682_priv *rt5682, struct device *dev)
{}
EXPORT_SYMBOL_GPL();

int rt5682_get_ldo1(struct rt5682_priv *rt5682, struct device *dev)
{}
EXPORT_SYMBOL_GPL();

void rt5682_calibrate(struct rt5682_priv *rt5682)
{}
EXPORT_SYMBOL_GPL();

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