linux/sound/soc/codecs/da7213.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * DA7213 ALSA SoC Codec Driver
 *
 * Copyright (c) 2013 Dialog Semiconductor
 *
 * Author: Adam Thomson <[email protected]>
 * Based on DA9055 ALSA SoC codec driver.
 */

#include <linux/acpi.h>
#include <linux/of.h>
#include <linux/property.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <linux/pm_runtime.h>
#include <sound/soc.h>
#include <sound/initval.h>
#include <sound/tlv.h>

#include <sound/da7213.h>
#include "da7213.h"


/* Gain and Volume */
static const DECLARE_TLV_DB_RANGE(aux_vol_tlv,
	/* -54dB */
	0x0, 0x11, TLV_DB_SCALE_ITEM(-5400, 0, 0),
	/* -52.5dB to 15dB */
	0x12, 0x3f, TLV_DB_SCALE_ITEM(-5250, 150, 0)
);

static const DECLARE_TLV_DB_RANGE(digital_gain_tlv,
	0x0, 0x07, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
	/* -78dB to 12dB */
	0x08, 0x7f, TLV_DB_SCALE_ITEM(-7800, 75, 0)
);

static const DECLARE_TLV_DB_RANGE(alc_analog_gain_tlv,
	0x0, 0x0, TLV_DB_SCALE_ITEM(TLV_DB_GAIN_MUTE, 0, 1),
	/* 0dB to 36dB */
	0x01, 0x07, TLV_DB_SCALE_ITEM(0, 600, 0)
);

static const DECLARE_TLV_DB_SCALE(mic_vol_tlv, -600, 600, 0);
static const DECLARE_TLV_DB_SCALE(mixin_gain_tlv, -450, 150, 0);
static const DECLARE_TLV_DB_SCALE(eq_gain_tlv, -1050, 150, 0);
static const DECLARE_TLV_DB_SCALE(hp_vol_tlv, -5700, 100, 0);
static const DECLARE_TLV_DB_SCALE(lineout_vol_tlv, -4800, 100, 0);
static const DECLARE_TLV_DB_SCALE(alc_threshold_tlv, -9450, 150, 0);
static const DECLARE_TLV_DB_SCALE(alc_gain_tlv, 0, 600, 0);
static const DECLARE_TLV_DB_SCALE(da7213_tonegen_gain_tlv, -4500, 300, 0);

/* ADC and DAC voice mode (8kHz) high pass cutoff value */
static const char * const da7213_voice_hpf_corner_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_dac_voice_hpf_corner,
			    DA7213_DAC_FILTERS1,
			    DA7213_VOICE_HPF_CORNER_SHIFT,
			    da7213_voice_hpf_corner_txt);

static SOC_ENUM_SINGLE_DECL(da7213_adc_voice_hpf_corner,
			    DA7213_ADC_FILTERS1,
			    DA7213_VOICE_HPF_CORNER_SHIFT,
			    da7213_voice_hpf_corner_txt);

/* ADC and DAC high pass filter cutoff value */
static const char * const da7213_audio_hpf_corner_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_dac_audio_hpf_corner,
			    DA7213_DAC_FILTERS1
			    , DA7213_AUDIO_HPF_CORNER_SHIFT,
			    da7213_audio_hpf_corner_txt);

static SOC_ENUM_SINGLE_DECL(da7213_adc_audio_hpf_corner,
			    DA7213_ADC_FILTERS1,
			    DA7213_AUDIO_HPF_CORNER_SHIFT,
			    da7213_audio_hpf_corner_txt);

static const char * const da7213_tonegen_dtmf_key_txt[] =;

static const struct soc_enum da7213_tonegen_dtmf_key =;

static const char * const da7213_tonegen_swg_sel_txt[] =;

static const struct soc_enum da7213_tonegen_swg_sel =;

/* Gain ramping rate value */
static const char * const da7213_gain_ramp_rate_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_gain_ramp_rate,
			    DA7213_GAIN_RAMP_CTRL,
			    DA7213_GAIN_RAMP_RATE_SHIFT,
			    da7213_gain_ramp_rate_txt);

/* DAC noise gate setup time value */
static const char * const da7213_dac_ng_setup_time_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_dac_ng_setup_time,
			    DA7213_DAC_NG_SETUP_TIME,
			    DA7213_DAC_NG_SETUP_TIME_SHIFT,
			    da7213_dac_ng_setup_time_txt);

/* DAC noise gate rampup rate value */
static const char * const da7213_dac_ng_rampup_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_dac_ng_rampup_rate,
			    DA7213_DAC_NG_SETUP_TIME,
			    DA7213_DAC_NG_RAMPUP_RATE_SHIFT,
			    da7213_dac_ng_rampup_txt);

/* DAC noise gate rampdown rate value */
static const char * const da7213_dac_ng_rampdown_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_dac_ng_rampdown_rate,
			    DA7213_DAC_NG_SETUP_TIME,
			    DA7213_DAC_NG_RAMPDN_RATE_SHIFT,
			    da7213_dac_ng_rampdown_txt);

/* DAC soft mute rate value */
static const char * const da7213_dac_soft_mute_rate_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_dac_soft_mute_rate,
			    DA7213_DAC_FILTERS5,
			    DA7213_DAC_SOFTMUTE_RATE_SHIFT,
			    da7213_dac_soft_mute_rate_txt);

/* ALC Attack Rate select */
static const char * const da7213_alc_attack_rate_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_alc_attack_rate,
			    DA7213_ALC_CTRL2,
			    DA7213_ALC_ATTACK_SHIFT,
			    da7213_alc_attack_rate_txt);

/* ALC Release Rate select */
static const char * const da7213_alc_release_rate_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_alc_release_rate,
			    DA7213_ALC_CTRL2,
			    DA7213_ALC_RELEASE_SHIFT,
			    da7213_alc_release_rate_txt);

/* ALC Hold Time select */
static const char * const da7213_alc_hold_time_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_alc_hold_time,
			    DA7213_ALC_CTRL3,
			    DA7213_ALC_HOLD_SHIFT,
			    da7213_alc_hold_time_txt);

/* ALC Input Signal Tracking rate select */
static const char * const da7213_alc_integ_rate_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_alc_integ_attack_rate,
			    DA7213_ALC_CTRL3,
			    DA7213_ALC_INTEG_ATTACK_SHIFT,
			    da7213_alc_integ_rate_txt);

static SOC_ENUM_SINGLE_DECL(da7213_alc_integ_release_rate,
			    DA7213_ALC_CTRL3,
			    DA7213_ALC_INTEG_RELEASE_SHIFT,
			    da7213_alc_integ_rate_txt);


/*
 * Control Functions
 */

/* Locked Kcontrol calls */
static int da7213_volsw_locked_get(struct snd_kcontrol *kcontrol,
				   struct snd_ctl_elem_value *ucontrol)
{}

static int da7213_volsw_locked_put(struct snd_kcontrol *kcontrol,
				   struct snd_ctl_elem_value *ucontrol)
{}

static int da7213_enum_locked_get(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{}

static int da7213_enum_locked_put(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{}

/* ALC */
static int da7213_get_alc_data(struct snd_soc_component *component, u8 reg_val)
{}

static void da7213_alc_calib_man(struct snd_soc_component *component)
{}

static void da7213_alc_calib_auto(struct snd_soc_component *component)
{}

static void da7213_alc_calib(struct snd_soc_component *component)
{}

static int da7213_put_mixin_gain(struct snd_kcontrol *kcontrol,
				struct snd_ctl_elem_value *ucontrol)
{}

static int da7213_put_alc_sw(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_value *ucontrol)
{}

/* ToneGen */
static int da7213_tonegen_freq_get(struct snd_kcontrol *kcontrol,
				   struct snd_ctl_elem_value *ucontrol)
{}

static int da7213_tonegen_freq_put(struct snd_kcontrol *kcontrol,
				   struct snd_ctl_elem_value *ucontrol)
{}

/*
 * KControls
 */

static const struct snd_kcontrol_new da7213_snd_controls[] =;


/*
 * DAPM
 */

/*
 * Enums
 */

/* MIC PGA source select */
static const char * const da7213_mic_amp_in_sel_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_mic_1_amp_in_sel,
			    DA7213_MIC_1_CTRL,
			    DA7213_MIC_AMP_IN_SEL_SHIFT,
			    da7213_mic_amp_in_sel_txt);
static const struct snd_kcontrol_new da7213_mic_1_amp_in_sel_mux =;

static SOC_ENUM_SINGLE_DECL(da7213_mic_2_amp_in_sel,
			    DA7213_MIC_2_CTRL,
			    DA7213_MIC_AMP_IN_SEL_SHIFT,
			    da7213_mic_amp_in_sel_txt);
static const struct snd_kcontrol_new da7213_mic_2_amp_in_sel_mux =;

/* DAI routing select */
static const char * const da7213_dai_src_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_dai_l_src,
			    DA7213_DIG_ROUTING_DAI,
			    DA7213_DAI_L_SRC_SHIFT,
			    da7213_dai_src_txt);
static const struct snd_kcontrol_new da7213_dai_l_src_mux =;

static SOC_ENUM_SINGLE_DECL(da7213_dai_r_src,
			    DA7213_DIG_ROUTING_DAI,
			    DA7213_DAI_R_SRC_SHIFT,
			    da7213_dai_src_txt);
static const struct snd_kcontrol_new da7213_dai_r_src_mux =;

/* DAC routing select */
static const char * const da7213_dac_src_txt[] =;

static SOC_ENUM_SINGLE_DECL(da7213_dac_l_src,
			    DA7213_DIG_ROUTING_DAC,
			    DA7213_DAC_L_SRC_SHIFT,
			    da7213_dac_src_txt);
static const struct snd_kcontrol_new da7213_dac_l_src_mux =;

static SOC_ENUM_SINGLE_DECL(da7213_dac_r_src,
			    DA7213_DIG_ROUTING_DAC,
			    DA7213_DAC_R_SRC_SHIFT,
			    da7213_dac_src_txt);
static const struct snd_kcontrol_new da7213_dac_r_src_mux =;

/*
 * Mixer Controls
 */

/* Mixin Left */
static const struct snd_kcontrol_new da7213_dapm_mixinl_controls[] =;

/* Mixin Right */
static const struct snd_kcontrol_new da7213_dapm_mixinr_controls[] =;

/* Mixout Left */
static const struct snd_kcontrol_new da7213_dapm_mixoutl_controls[] =;

/* Mixout Right */
static const struct snd_kcontrol_new da7213_dapm_mixoutr_controls[] =;


/*
 * DAPM Events
 */

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


/*
 * DAPM widgets
 */

static const struct snd_soc_dapm_widget da7213_dapm_widgets[] =;


/*
 * DAPM audio route definition
 */

static const struct snd_soc_dapm_route da7213_audio_map[] =;

static const struct reg_default da7213_reg_defaults[] =;

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

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

static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
{}

static int da7213_mute(struct snd_soc_dai *dai, int mute, int direction)
{}

#define DA7213_FORMATS

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

/* Supported PLL input frequencies are 32KHz, 5MHz - 54MHz. */
static int _da7213_set_component_pll(struct snd_soc_component *component,
				     int pll_id, int source,
				     unsigned int fref, unsigned int fout)
{}

static int da7213_set_component_pll(struct snd_soc_component *component,
				    int pll_id, int source,
				    unsigned int fref, unsigned int fout)
{}

/*
 * Select below from Sound Card, not Auto
 *	SND_SOC_DAIFMT_CBC_CFC
 *	SND_SOC_DAIFMT_CBP_CFP
 */
static const u64 da7213_dai_formats =;

/* DAI operations */
static const struct snd_soc_dai_ops da7213_dai_ops =;

static struct snd_soc_dai_driver da7213_dai =;

static int da7213_set_auto_pll(struct snd_soc_component *component, bool enable)
{}

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

#if defined(CONFIG_OF)
/* DT */
static const struct of_device_id da7213_of_match[] =;
MODULE_DEVICE_TABLE(of, da7213_of_match);
#endif

#ifdef CONFIG_ACPI
static const struct acpi_device_id da7213_acpi_match[] =;
MODULE_DEVICE_TABLE(acpi, da7213_acpi_match);
#endif

static enum da7213_micbias_voltage
	da7213_of_micbias_lvl(struct snd_soc_component *component, u32 val)
{}

static enum da7213_dmic_data_sel
	da7213_of_dmic_data_sel(struct snd_soc_component *component, const char *str)
{}

static enum da7213_dmic_samplephase
	da7213_of_dmic_samplephase(struct snd_soc_component *component, const char *str)
{}

static enum da7213_dmic_clk_rate
	da7213_of_dmic_clkrate(struct snd_soc_component *component, u32 val)
{}

static struct da7213_platform_data
	*da7213_fw_to_pdata(struct snd_soc_component *component)
{}

static int da7213_probe(struct snd_soc_component *component)
{}

static const struct snd_soc_component_driver soc_component_dev_da7213 =;

static const struct regmap_config da7213_regmap_config =;

static void da7213_power_off(void *data)
{}

static const char *da7213_supply_names[DA7213_NUM_SUPPLIES] =;

static int da7213_i2c_probe(struct i2c_client *i2c)
{}

static void da7213_i2c_remove(struct i2c_client *i2c)
{}

static int __maybe_unused da7213_runtime_suspend(struct device *dev)
{}

static int __maybe_unused da7213_runtime_resume(struct device *dev)
{}

static const struct dev_pm_ops da7213_pm =;

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

/* I2C codec control layer */
static struct i2c_driver da7213_i2c_driver =;

module_i2c_driver();

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