linux/sound/soc/codecs/twl4030.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * ALSA SoC TWL4030 codec driver
 *
 * Author:      Steve Sakoman, <[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/of.h>
#include <linux/of_gpio.h>
#include <linux/mfd/twl.h>
#include <linux/slab.h>
#include <linux/gpio.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#include <sound/initval.h>
#include <sound/tlv.h>

/* Register descriptions are here */
#include <linux/mfd/twl4030-audio.h>

/* TWL4030 PMBR1 Register */
#define TWL4030_PMBR1_REG
/* TWL4030 PMBR1 Register GPIO6 mux bits */
#define TWL4030_GPIO6_PWM0_MUTE(value)

#define TWL4030_CACHEREGNUM

struct twl4030_board_params {};

/* codec private data */
struct twl4030_priv {};

static void tw4030_init_ctl_cache(struct twl4030_priv *twl4030)
{}

static unsigned int twl4030_read(struct snd_soc_component *component, unsigned int reg)
{}

static bool twl4030_can_write_to_chip(struct twl4030_priv *twl4030,
				      unsigned int reg)
{}

static int twl4030_write(struct snd_soc_component *component, unsigned int reg,
			 unsigned int value)
{}

static inline void twl4030_wait_ms(int time)
{}

static void twl4030_codec_enable(struct snd_soc_component *component, int enable)
{}

static void
twl4030_get_board_param_values(struct twl4030_board_params *board_params,
			       struct device_node *node)
{}

static struct twl4030_board_params*
twl4030_get_board_params(struct snd_soc_component *component)
{}

static void twl4030_init_chip(struct snd_soc_component *component)
{}

static void twl4030_apll_enable(struct snd_soc_component *component, int enable)
{}

/* Earpiece */
static const struct snd_kcontrol_new twl4030_dapm_earpiece_controls[] =;

/* PreDrive Left */
static const struct snd_kcontrol_new twl4030_dapm_predrivel_controls[] =;

/* PreDrive Right */
static const struct snd_kcontrol_new twl4030_dapm_predriver_controls[] =;

/* Headset Left */
static const struct snd_kcontrol_new twl4030_dapm_hsol_controls[] =;

/* Headset Right */
static const struct snd_kcontrol_new twl4030_dapm_hsor_controls[] =;

/* Carkit Left */
static const struct snd_kcontrol_new twl4030_dapm_carkitl_controls[] =;

/* Carkit Right */
static const struct snd_kcontrol_new twl4030_dapm_carkitr_controls[] =;

/* Handsfree Left */
static const char *twl4030_handsfreel_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_handsfreel_enum,
			    TWL4030_REG_HFL_CTL, 0,
			    twl4030_handsfreel_texts);

static const struct snd_kcontrol_new twl4030_dapm_handsfreel_control =;

/* Handsfree Left virtual mute */
static const struct snd_kcontrol_new twl4030_dapm_handsfreelmute_control =;

/* Handsfree Right */
static const char *twl4030_handsfreer_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_handsfreer_enum,
			    TWL4030_REG_HFR_CTL, 0,
			    twl4030_handsfreer_texts);

static const struct snd_kcontrol_new twl4030_dapm_handsfreer_control =;

/* Handsfree Right virtual mute */
static const struct snd_kcontrol_new twl4030_dapm_handsfreermute_control =;

/* Vibra */
/* Vibra audio path selection */
static const char *twl4030_vibra_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_vibra_enum,
			    TWL4030_REG_VIBRA_CTL, 2,
			    twl4030_vibra_texts);

static const struct snd_kcontrol_new twl4030_dapm_vibra_control =;

/* Vibra path selection: local vibrator (PWM) or audio driven */
static const char *twl4030_vibrapath_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_vibrapath_enum,
			    TWL4030_REG_VIBRA_CTL, 4,
			    twl4030_vibrapath_texts);

static const struct snd_kcontrol_new twl4030_dapm_vibrapath_control =;

/* Left analog microphone selection */
static const struct snd_kcontrol_new twl4030_dapm_analoglmic_controls[] =;

/* Right analog microphone selection */
static const struct snd_kcontrol_new twl4030_dapm_analogrmic_controls[] =;

/* TX1 L/R Analog/Digital microphone selection */
static const char *twl4030_micpathtx1_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_micpathtx1_enum,
			    TWL4030_REG_ADCMICSEL, 0,
			    twl4030_micpathtx1_texts);

static const struct snd_kcontrol_new twl4030_dapm_micpathtx1_control =;

/* TX2 L/R Analog/Digital microphone selection */
static const char *twl4030_micpathtx2_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_micpathtx2_enum,
			    TWL4030_REG_ADCMICSEL, 2,
			    twl4030_micpathtx2_texts);

static const struct snd_kcontrol_new twl4030_dapm_micpathtx2_control =;

/* Analog bypass for AudioR1 */
static const struct snd_kcontrol_new twl4030_dapm_abypassr1_control =;

/* Analog bypass for AudioL1 */
static const struct snd_kcontrol_new twl4030_dapm_abypassl1_control =;

/* Analog bypass for AudioR2 */
static const struct snd_kcontrol_new twl4030_dapm_abypassr2_control =;

/* Analog bypass for AudioL2 */
static const struct snd_kcontrol_new twl4030_dapm_abypassl2_control =;

/* Analog bypass for Voice */
static const struct snd_kcontrol_new twl4030_dapm_abypassv_control =;

/* Digital bypass gain, mute instead of -30dB */
static const DECLARE_TLV_DB_RANGE(twl4030_dapm_dbypass_tlv,
	0, 1, TLV_DB_SCALE_ITEM(-3000, 600, 1),
	2, 3, TLV_DB_SCALE_ITEM(-2400, 0, 0),
	4, 7, TLV_DB_SCALE_ITEM(-1800, 600, 0)
);

/* Digital bypass left (TX1L -> RX2L) */
static const struct snd_kcontrol_new twl4030_dapm_dbypassl_control =;

/* Digital bypass right (TX1R -> RX2R) */
static const struct snd_kcontrol_new twl4030_dapm_dbypassr_control =;

/*
 * Voice Sidetone GAIN volume control:
 * from -51 to -10 dB in 1 dB steps (mute instead of -51 dB)
 */
static DECLARE_TLV_DB_SCALE(twl4030_dapm_dbypassv_tlv, -5100, 100, 1);

/* Digital bypass voice: sidetone (VUL -> VDL)*/
static const struct snd_kcontrol_new twl4030_dapm_dbypassv_control =;

/*
 * Output PGA builder:
 * Handle the muting and unmuting of the given output (turning off the
 * amplifier associated with the output pin)
 * On mute bypass the reg_cache and write 0 to the register
 * On unmute: restore the register content from the reg_cache
 * Outputs handled in this way:  Earpiece, PreDrivL/R, CarkitL/R
 */
#define TWL4030_OUTPUT_PGA(pin_name, reg, mask)

TWL4030_OUTPUT_PGA(earpiece, TWL4030_REG_EAR_CTL, TWL4030_EAR_GAIN);
TWL4030_OUTPUT_PGA(predrivel, TWL4030_REG_PREDL_CTL, TWL4030_PREDL_GAIN);
TWL4030_OUTPUT_PGA(predriver, TWL4030_REG_PREDR_CTL, TWL4030_PREDR_GAIN);
TWL4030_OUTPUT_PGA(carkitl, TWL4030_REG_PRECKL_CTL, TWL4030_PRECKL_GAIN);
TWL4030_OUTPUT_PGA(carkitr, TWL4030_REG_PRECKR_CTL, TWL4030_PRECKR_GAIN);

static void handsfree_ramp(struct snd_soc_component *component, int reg, int ramp)
{}

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

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

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

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

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

static void headset_ramp(struct snd_soc_component *component, int ramp)
{}

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

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

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

/*
 * Some of the gain controls in TWL (mostly those which are associated with
 * the outputs) are implemented in an interesting way:
 * 0x0 : Power down (mute)
 * 0x1 : 6dB
 * 0x2 : 0 dB
 * 0x3 : -6 dB
 * Inverting not going to help with these.
 * Custom volsw and volsw_2r get/put functions to handle these gain bits.
 */
static int snd_soc_get_volsw_twl4030(struct snd_kcontrol *kcontrol,
				     struct snd_ctl_elem_value *ucontrol)
{}

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

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

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

/* Codec operation modes */
static const char *twl4030_op_modes_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_op_modes_enum,
			    TWL4030_REG_CODEC_MODE, 0,
			    twl4030_op_modes_texts);

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

/*
 * FGAIN volume control:
 * from -62 to 0 dB in 1 dB steps (mute instead of -63 dB)
 */
static DECLARE_TLV_DB_SCALE(digital_fine_tlv, -6300, 100, 1);

/*
 * CGAIN volume control:
 * 0 dB to 12 dB in 6 dB steps
 * value 2 and 3 means 12 dB
 */
static DECLARE_TLV_DB_SCALE(digital_coarse_tlv, 0, 600, 0);

/*
 * Voice Downlink GAIN volume control:
 * from -37 to 12 dB in 1 dB steps (mute instead of -37 dB)
 */
static DECLARE_TLV_DB_SCALE(digital_voice_downlink_tlv, -3700, 100, 1);

/*
 * Analog playback gain
 * -24 dB to 12 dB in 2 dB steps
 */
static DECLARE_TLV_DB_SCALE(analog_tlv, -2400, 200, 0);

/*
 * Gain controls tied to outputs
 * -6 dB to 6 dB in 6 dB steps (mute instead of -12)
 */
static DECLARE_TLV_DB_SCALE(output_tvl, -1200, 600, 1);

/*
 * Gain control for earpiece amplifier
 * 0 dB to 12 dB in 6 dB steps (mute instead of -6)
 */
static DECLARE_TLV_DB_SCALE(output_ear_tvl, -600, 600, 1);

/*
 * Capture gain after the ADCs
 * from 0 dB to 31 dB in 1 dB steps
 */
static DECLARE_TLV_DB_SCALE(digital_capture_tlv, 0, 100, 0);

/*
 * Gain control for input amplifiers
 * 0 dB to 30 dB in 6 dB steps
 */
static DECLARE_TLV_DB_SCALE(input_gain_tlv, 0, 600, 0);

/* AVADC clock priority */
static const char *twl4030_avadc_clk_priority_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_avadc_clk_priority_enum,
			    TWL4030_REG_AVADC_CTL, 2,
			    twl4030_avadc_clk_priority_texts);

static const char *twl4030_rampdelay_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_rampdelay_enum,
			    TWL4030_REG_HS_POPN_SET, 2,
			    twl4030_rampdelay_texts);

/* Vibra H-bridge direction mode */
static const char *twl4030_vibradirmode_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_vibradirmode_enum,
			    TWL4030_REG_VIBRA_CTL, 5,
			    twl4030_vibradirmode_texts);

/* Vibra H-bridge direction */
static const char *twl4030_vibradir_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_vibradir_enum,
			    TWL4030_REG_VIBRA_CTL, 1,
			    twl4030_vibradir_texts);

/* Digimic Left and right swapping */
static const char *twl4030_digimicswap_texts[] =;

static SOC_ENUM_SINGLE_DECL(twl4030_digimicswap_enum,
			    TWL4030_REG_MISC_SET_1, 0,
			    twl4030_digimicswap_texts);

static const struct snd_kcontrol_new twl4030_snd_controls[] =;

static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] =;

static const struct snd_soc_dapm_route intercon[] =;

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

static void twl4030_constraints(struct twl4030_priv *twl4030,
				struct snd_pcm_substream *mst_substream)
{}

/* In case of 4 channel mode, the RX1 L/R for playback and the TX2 L/R for
 * capture has to be enabled/disabled. */
static void twl4030_tdm_enable(struct snd_soc_component *component, int direction,
			       int enable)
{}

static int twl4030_startup(struct snd_pcm_substream *substream,
			   struct snd_soc_dai *dai)
{}

static void twl4030_shutdown(struct snd_pcm_substream *substream,
			     struct snd_soc_dai *dai)
{}

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

static int twl4030_set_dai_sysclk(struct snd_soc_dai *codec_dai, int clk_id,
				  unsigned int freq, int dir)
{}

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

static int twl4030_set_tristate(struct snd_soc_dai *dai, int tristate)
{}

/* In case of voice mode, the RX1 L(VRX) for downlink and the TX2 L/R
 * (VTXL, VTXR) for uplink has to be enabled/disabled. */
static void twl4030_voice_enable(struct snd_soc_component *component, int direction,
				 int enable)
{}

static int twl4030_voice_startup(struct snd_pcm_substream *substream,
				 struct snd_soc_dai *dai)
{}

static void twl4030_voice_shutdown(struct snd_pcm_substream *substream,
				   struct snd_soc_dai *dai)
{}

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

static int twl4030_voice_set_dai_sysclk(struct snd_soc_dai *codec_dai,
					int clk_id, unsigned int freq, int dir)
{}

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

static int twl4030_voice_set_tristate(struct snd_soc_dai *dai, int tristate)
{}

#define TWL4030_RATES
#define TWL4030_FORMATS

static const struct snd_soc_dai_ops twl4030_dai_hifi_ops =;

static const struct snd_soc_dai_ops twl4030_dai_voice_ops =;

static struct snd_soc_dai_driver twl4030_dai[] =;

static int twl4030_soc_probe(struct snd_soc_component *component)
{}

static void twl4030_soc_remove(struct snd_soc_component *component)
{}

static const struct snd_soc_component_driver soc_component_dev_twl4030 =;

static int twl4030_codec_probe(struct platform_device *pdev)
{}

MODULE_ALIAS();

static struct platform_driver twl4030_codec_driver =;

module_platform_driver();

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