linux/sound/soc/codecs/wm8903.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * wm8903.c  --  WM8903 ALSA SoC Audio driver
 *
 * Copyright 2008-12 Wolfson Microelectronics
 * Copyright 2011-2012 NVIDIA, Inc.
 *
 * Author: Mark Brown <[email protected]>
 *
 * TODO:
 *  - TDM mode configuration.
 */

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/completion.h>
#include <linux/delay.h>
#include <linux/gpio/driver.h>
#include <linux/pm.h>
#include <linux/i2c.h>
#include <linux/regmap.h>
#include <linux/regulator/consumer.h>
#include <linux/slab.h>
#include <linux/irq.h>
#include <linux/mutex.h>
#include <sound/core.h>
#include <sound/jack.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
#include <sound/tlv.h>
#include <sound/soc.h>
#include <sound/initval.h>
#include <sound/wm8903.h>
#include <trace/events/asoc.h>

#include "wm8903.h"

/* Register defaults at reset */
static const struct reg_default wm8903_reg_defaults[] =;

#define WM8903_NUM_SUPPLIES
static const char *wm8903_supply_names[WM8903_NUM_SUPPLIES] =;

struct wm8903_priv {};

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

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

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

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

#define WM8903_DCS_MODE_WRITE_STOP
#define WM8903_DCS_MODE_START_STOP

static void wm8903_seq_notifier(struct snd_soc_component *component,
				enum snd_soc_dapm_type event, int subseq)
{}

/*
 * When used with DAC outputs only the WM8903 charge pump supports
 * operation in class W mode, providing very low power consumption
 * when used with digital sources.  Enable and disable this mode
 * automatically depending on the mixer configuration.
 *
 * All the relevant controls are simple switches.
 */
static int wm8903_class_w_put(struct snd_kcontrol *kcontrol,
			      struct snd_ctl_elem_value *ucontrol)
{}

#define SOC_DAPM_SINGLE_W(xname, reg, shift, max, invert)


static int wm8903_deemph[] =;

static int wm8903_set_deemph(struct snd_soc_component *component)
{}

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

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

/* ALSA can only do steps of .01dB */
static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);

static const DECLARE_TLV_DB_SCALE(dac_boost_tlv, 0, 600, 0);

static const DECLARE_TLV_DB_SCALE(digital_sidetone_tlv, -3600, 300, 0);
static const DECLARE_TLV_DB_SCALE(out_tlv, -5700, 100, 0);

static const DECLARE_TLV_DB_SCALE(drc_tlv_thresh, 0, 75, 0);
static const DECLARE_TLV_DB_SCALE(drc_tlv_amp, -2250, 75, 0);
static const DECLARE_TLV_DB_SCALE(drc_tlv_min, 0, 600, 0);
static const DECLARE_TLV_DB_SCALE(drc_tlv_max, 1200, 600, 0);
static const DECLARE_TLV_DB_SCALE(drc_tlv_startup, -300, 50, 0);

static const char *hpf_mode_text[] =;

static SOC_ENUM_SINGLE_DECL(hpf_mode,
			    WM8903_ADC_DIGITAL_0, 5, hpf_mode_text);

static const char *osr_text[] =;

static SOC_ENUM_SINGLE_DECL(adc_osr,
			    WM8903_ANALOGUE_ADC_0, 0, osr_text);

static SOC_ENUM_SINGLE_DECL(dac_osr,
			    WM8903_DAC_DIGITAL_1, 0, osr_text);

static const char *drc_slope_text[] =;

static SOC_ENUM_SINGLE_DECL(drc_slope_r0,
			    WM8903_DRC_2, 3, drc_slope_text);

static SOC_ENUM_SINGLE_DECL(drc_slope_r1,
			    WM8903_DRC_2, 0, drc_slope_text);

static const char *drc_attack_text[] =;

static SOC_ENUM_SINGLE_DECL(drc_attack,
			    WM8903_DRC_1, 12, drc_attack_text);

static const char *drc_decay_text[] =;

static SOC_ENUM_SINGLE_DECL(drc_decay,
			    WM8903_DRC_1, 8, drc_decay_text);

static const char *drc_ff_delay_text[] =;

static SOC_ENUM_SINGLE_DECL(drc_ff_delay,
			    WM8903_DRC_0, 5, drc_ff_delay_text);

static const char *drc_qr_decay_text[] =;

static SOC_ENUM_SINGLE_DECL(drc_qr_decay,
			    WM8903_DRC_1, 4, drc_qr_decay_text);

static const char *drc_smoothing_text[] =;

static SOC_ENUM_SINGLE_DECL(drc_smoothing,
			    WM8903_DRC_0, 11, drc_smoothing_text);

static const char *soft_mute_text[] =;

static SOC_ENUM_SINGLE_DECL(soft_mute,
			    WM8903_DAC_DIGITAL_1, 10, soft_mute_text);

static const char *mute_mode_text[] =;

static SOC_ENUM_SINGLE_DECL(mute_mode,
			    WM8903_DAC_DIGITAL_1, 9, mute_mode_text);

static const char *companding_text[] =;

static SOC_ENUM_SINGLE_DECL(dac_companding,
			    WM8903_AUDIO_INTERFACE_0, 0, companding_text);

static SOC_ENUM_SINGLE_DECL(adc_companding,
			    WM8903_AUDIO_INTERFACE_0, 2, companding_text);

static const char *input_mode_text[] =;

static SOC_ENUM_SINGLE_DECL(linput_mode_enum,
			    WM8903_ANALOGUE_LEFT_INPUT_1, 0, input_mode_text);

static SOC_ENUM_SINGLE_DECL(rinput_mode_enum,
			    WM8903_ANALOGUE_RIGHT_INPUT_1, 0, input_mode_text);

static const char *linput_mux_text[] =;

static SOC_ENUM_SINGLE_DECL(linput_enum,
			    WM8903_ANALOGUE_LEFT_INPUT_1, 2, linput_mux_text);

static SOC_ENUM_SINGLE_DECL(linput_inv_enum,
			    WM8903_ANALOGUE_LEFT_INPUT_1, 4, linput_mux_text);

static const char *rinput_mux_text[] =;

static SOC_ENUM_SINGLE_DECL(rinput_enum,
			    WM8903_ANALOGUE_RIGHT_INPUT_1, 2, rinput_mux_text);

static SOC_ENUM_SINGLE_DECL(rinput_inv_enum,
			    WM8903_ANALOGUE_RIGHT_INPUT_1, 4, rinput_mux_text);


static const char *sidetone_text[] =;

static SOC_ENUM_SINGLE_DECL(lsidetone_enum,
			    WM8903_DAC_DIGITAL_0, 2, sidetone_text);

static SOC_ENUM_SINGLE_DECL(rsidetone_enum,
			    WM8903_DAC_DIGITAL_0, 0, sidetone_text);

static const char *adcinput_text[] =;

static SOC_ENUM_SINGLE_DECL(adcinput_enum,
			    WM8903_CLOCK_RATE_TEST_4, 9, adcinput_text);

static const char *aif_text[] =;

static SOC_ENUM_SINGLE_DECL(lcapture_enum,
			    WM8903_AUDIO_INTERFACE_0, 7, aif_text);

static SOC_ENUM_SINGLE_DECL(rcapture_enum,
			    WM8903_AUDIO_INTERFACE_0, 6, aif_text);

static SOC_ENUM_SINGLE_DECL(lplay_enum,
			    WM8903_AUDIO_INTERFACE_0, 5, aif_text);

static SOC_ENUM_SINGLE_DECL(rplay_enum,
			    WM8903_AUDIO_INTERFACE_0, 4, aif_text);

static const struct snd_kcontrol_new wm8903_snd_controls[] =;

static const struct snd_kcontrol_new linput_mode_mux =;

static const struct snd_kcontrol_new rinput_mode_mux =;

static const struct snd_kcontrol_new linput_mux =;

static const struct snd_kcontrol_new linput_inv_mux =;

static const struct snd_kcontrol_new rinput_mux =;

static const struct snd_kcontrol_new rinput_inv_mux =;

static const struct snd_kcontrol_new lsidetone_mux =;

static const struct snd_kcontrol_new rsidetone_mux =;

static const struct snd_kcontrol_new adcinput_mux =;

static const struct snd_kcontrol_new lcapture_mux =;

static const struct snd_kcontrol_new rcapture_mux =;

static const struct snd_kcontrol_new lplay_mux =;

static const struct snd_kcontrol_new rplay_mux =;

static const struct snd_kcontrol_new left_output_mixer[] =;

static const struct snd_kcontrol_new right_output_mixer[] =;

static const struct snd_kcontrol_new left_speaker_mixer[] =;

static const struct snd_kcontrol_new right_speaker_mixer[] =;

static const struct snd_soc_dapm_widget wm8903_dapm_widgets[] =;

static const struct snd_soc_dapm_route wm8903_intercon[] =;

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

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

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

static int wm8903_mute(struct snd_soc_dai *codec_dai, int mute, int direction)
{}

/* Lookup table for CLK_SYS/fs ratio.  256fs or more is recommended
 * for optimal performance so we list the lower rates first and match
 * on the last match we find. */
static struct {} clk_sys_ratios[] =;

/* CLK_SYS/BCLK ratios - multiplied by 10 due to .5s */
static struct {} bclk_divs[] =;

/* Sample rates for DSP */
static struct {} sample_rates[] =;

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

/**
 * wm8903_mic_detect - Enable microphone detection via the WM8903 IRQ
 *
 * @component:  WM8903 component
 * @jack:   jack to report detection events on
 * @det:    value to report for presence detection
 * @shrt:   value to report for short detection
 *
 * Enable microphone detection via IRQ on the WM8903.  If GPIOs are
 * being used to bring out signals to the processor then only platform
 * data configuration is needed for WM8903 and processor GPIOs should
 * be configured using snd_soc_jack_add_gpios() instead.
 *
 * The current threasholds for detection should be configured using
 * micdet_cfg in the platform data.  Using this function will force on
 * the microphone bias for the device.
 */
int wm8903_mic_detect(struct snd_soc_component *component, struct snd_soc_jack *jack,
		      int det, int shrt)
{}
EXPORT_SYMBOL_GPL();

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

#define WM8903_PLAYBACK_RATES

#define WM8903_CAPTURE_RATES

#define WM8903_FORMATS

static const struct snd_soc_dai_ops wm8903_dai_ops =;

static struct snd_soc_dai_driver wm8903_dai =;

static int wm8903_resume(struct snd_soc_component *component)
{}

#ifdef CONFIG_GPIOLIB
static int wm8903_gpio_request(struct gpio_chip *chip, unsigned offset)
{}

static int wm8903_gpio_direction_in(struct gpio_chip *chip, unsigned offset)
{}

static int wm8903_gpio_get(struct gpio_chip *chip, unsigned offset)
{}

static int wm8903_gpio_direction_out(struct gpio_chip *chip,
				     unsigned offset, int value)
{}

static void wm8903_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
{}

static const struct gpio_chip wm8903_template_chip =;

static void wm8903_init_gpio(struct wm8903_priv *wm8903)
{}

static void wm8903_free_gpio(struct wm8903_priv *wm8903)
{}
#else
static void wm8903_init_gpio(struct wm8903_priv *wm8903)
{
}

static void wm8903_free_gpio(struct wm8903_priv *wm8903)
{
}
#endif

static const struct snd_soc_component_driver soc_component_dev_wm8903 =;

static const struct regmap_config wm8903_regmap =;

static int wm8903_set_pdata_irq_trigger(struct i2c_client *i2c,
					struct wm8903_platform_data *pdata)
{}

static int wm8903_set_pdata_from_of(struct i2c_client *i2c,
				    struct wm8903_platform_data *pdata)
{}

static int wm8903_i2c_probe(struct i2c_client *i2c)
{}

static void wm8903_i2c_remove(struct i2c_client *client)
{}

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

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

static struct i2c_driver wm8903_i2c_driver =;

module_i2c_driver();

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