2016-02-18 09:28:49 +08:00
|
|
|
/*
|
|
|
|
* max9867.c -- max9867 ALSA SoC Audio driver
|
|
|
|
*
|
|
|
|
* Copyright 2013-15 Maxim Integrated Products
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/regmap.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/tlv.h>
|
|
|
|
#include "max9867.h"
|
|
|
|
|
|
|
|
static const char *const max9867_spmode[] = {
|
|
|
|
"Stereo Diff", "Mono Diff",
|
|
|
|
"Stereo Cap", "Mono Cap",
|
|
|
|
"Stereo Single", "Mono Single",
|
|
|
|
"Stereo Single Fast", "Mono Single Fast"
|
|
|
|
};
|
|
|
|
static const char *const max9867_sidetone_text[] = {
|
|
|
|
"None", "Left", "Right", "LeftRight", "LeftRightDiv2",
|
|
|
|
};
|
|
|
|
static const char *const max9867_filter_text[] = {"IIR", "FIR"};
|
|
|
|
|
|
|
|
static SOC_ENUM_SINGLE_DECL(max9867_filter, MAX9867_CODECFLTR, 7,
|
|
|
|
max9867_filter_text);
|
|
|
|
static SOC_ENUM_SINGLE_DECL(max9867_spkmode, MAX9867_MODECONFIG, 0,
|
|
|
|
max9867_spmode);
|
|
|
|
static SOC_ENUM_SINGLE_DECL(max9867_sidetone, MAX9867_DACGAIN, 6,
|
|
|
|
max9867_sidetone_text);
|
|
|
|
static DECLARE_TLV_DB_SCALE(max9860_capture_tlv, -600, 200, 0);
|
|
|
|
static DECLARE_TLV_DB_SCALE(max9860_mic_tlv, 2000, 100, 1);
|
|
|
|
static DECLARE_TLV_DB_SCALE(max9860_adc_left_tlv, -1200, 100, 1);
|
|
|
|
static DECLARE_TLV_DB_SCALE(max9860_adc_right_tlv, -1200, 100, 1);
|
2016-09-28 08:29:19 +08:00
|
|
|
static const SNDRV_CTL_TLVD_DECLARE_DB_RANGE(max98088_micboost_tlv,
|
2016-02-18 09:28:49 +08:00
|
|
|
0, 1, TLV_DB_SCALE_ITEM(0, 2000, 0),
|
|
|
|
2, 2, TLV_DB_SCALE_ITEM(3000, 0, 0),
|
2016-09-28 08:29:19 +08:00
|
|
|
);
|
2016-02-18 09:28:49 +08:00
|
|
|
|
|
|
|
static const struct snd_kcontrol_new max9867_snd_controls[] = {
|
|
|
|
SOC_DOUBLE_R("Master Playback Volume", MAX9867_LEFTVOL,
|
|
|
|
MAX9867_RIGHTVOL, 0, 63, 1),
|
|
|
|
SOC_DOUBLE_R_TLV("Capture Volume", MAX9867_LEFTMICGAIN,
|
|
|
|
MAX9867_RIGHTMICGAIN,
|
|
|
|
0, 15, 1, max9860_capture_tlv),
|
|
|
|
SOC_DOUBLE_R_TLV("Mic Volume", MAX9867_LEFTMICGAIN,
|
|
|
|
MAX9867_RIGHTMICGAIN, 0, 31, 1, max9860_mic_tlv),
|
|
|
|
SOC_DOUBLE_R_TLV("Mic Boost Volume", MAX9867_LEFTMICGAIN,
|
|
|
|
MAX9867_RIGHTMICGAIN, 5, 3, 0, max98088_micboost_tlv),
|
|
|
|
SOC_ENUM("Digital Sidetone Src", max9867_sidetone),
|
|
|
|
SOC_SINGLE("Sidetone Volume", MAX9867_DACGAIN, 0, 31, 1),
|
|
|
|
SOC_SINGLE("DAC Volume", MAX9867_DACLEVEL, 4, 3, 0),
|
|
|
|
SOC_SINGLE("DAC Attenuation", MAX9867_DACLEVEL, 0, 15, 1),
|
|
|
|
SOC_SINGLE_TLV("ADC Left Volume", MAX9867_ADCLEVEL,
|
|
|
|
4, 15, 1, max9860_adc_left_tlv),
|
|
|
|
SOC_SINGLE_TLV("ADC Right Volume", MAX9867_ADCLEVEL,
|
|
|
|
0, 15, 1, max9860_adc_right_tlv),
|
|
|
|
SOC_ENUM("Speaker Mode", max9867_spkmode),
|
|
|
|
SOC_SINGLE("Volume Smoothing Switch", MAX9867_MODECONFIG, 6, 1, 0),
|
|
|
|
SOC_SINGLE("ZCD Switch", MAX9867_MODECONFIG, 5, 1, 0),
|
|
|
|
SOC_ENUM("DSP Filter", max9867_filter),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *const max9867_mux[] = {"None", "Mic", "Line", "Mic_Line"};
|
|
|
|
|
|
|
|
static SOC_ENUM_SINGLE_DECL(max9867_mux_enum,
|
|
|
|
MAX9867_INPUTCONFIG, MAX9867_INPUT_SHIFT,
|
|
|
|
max9867_mux);
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new max9867_dapm_mux_controls =
|
|
|
|
SOC_DAPM_ENUM("Route", max9867_mux_enum);
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new max9867_left_dapm_control =
|
|
|
|
SOC_DAPM_SINGLE("Switch", MAX9867_PWRMAN, 6, 1, 0);
|
|
|
|
static const struct snd_kcontrol_new max9867_right_dapm_control =
|
|
|
|
SOC_DAPM_SINGLE("Switch", MAX9867_PWRMAN, 5, 1, 0);
|
|
|
|
static const struct snd_kcontrol_new max9867_line_dapm_control =
|
|
|
|
SOC_DAPM_SINGLE("Switch", MAX9867_LEFTLINELVL, 6, 1, 1);
|
|
|
|
|
|
|
|
static const struct snd_soc_dapm_widget max9867_dapm_widgets[] = {
|
|
|
|
SND_SOC_DAPM_AIF_IN("DAI_OUT", "HiFi Playback", 0, SND_SOC_NOPM, 0, 0),
|
|
|
|
SND_SOC_DAPM_DAC("Left DAC", NULL, MAX9867_PWRMAN, 3, 0),
|
|
|
|
SND_SOC_DAPM_DAC("Right DAC", NULL, MAX9867_PWRMAN, 2, 0),
|
|
|
|
SND_SOC_DAPM_MIXER("Output Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_OUTPUT("HPOUT"),
|
|
|
|
|
|
|
|
SND_SOC_DAPM_AIF_IN("DAI_IN", "HiFi Capture", 0, SND_SOC_NOPM, 0, 0),
|
|
|
|
SND_SOC_DAPM_ADC("Left ADC", "HiFi Capture", MAX9867_PWRMAN, 1, 0),
|
|
|
|
SND_SOC_DAPM_ADC("Right ADC", "HiFi Capture", MAX9867_PWRMAN, 0, 0),
|
|
|
|
SND_SOC_DAPM_MUX("Input Mux", SND_SOC_NOPM, 0, 0,
|
|
|
|
&max9867_dapm_mux_controls),
|
|
|
|
|
|
|
|
SND_SOC_DAPM_MIXER("Input Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_SWITCH("Left Line", MAX9867_LEFTLINELVL, 6, 1,
|
|
|
|
&max9867_left_dapm_control),
|
|
|
|
SND_SOC_DAPM_SWITCH("Right Line", MAX9867_RIGTHLINELVL, 6, 1,
|
|
|
|
&max9867_right_dapm_control),
|
|
|
|
SND_SOC_DAPM_SWITCH("Line Mixer", SND_SOC_NOPM, 0, 0,
|
|
|
|
&max9867_line_dapm_control),
|
|
|
|
SND_SOC_DAPM_INPUT("LINE_IN"),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_soc_dapm_route max9867_audio_map[] = {
|
|
|
|
{"Left DAC", NULL, "DAI_OUT"},
|
|
|
|
{"Right DAC", NULL, "DAI_OUT"},
|
|
|
|
{"Output Mixer", NULL, "Left DAC"},
|
|
|
|
{"Output Mixer", NULL, "Right DAC"},
|
|
|
|
{"HPOUT", NULL, "Output Mixer"},
|
|
|
|
|
|
|
|
{"Left ADC", NULL, "DAI_IN"},
|
|
|
|
{"Right ADC", NULL, "DAI_IN"},
|
|
|
|
{"Input Mixer", NULL, "Left ADC"},
|
|
|
|
{"Input Mixer", NULL, "Right ADC"},
|
|
|
|
{"Input Mux", "Line", "Input Mixer"},
|
|
|
|
{"Input Mux", "Mic", "Input Mixer"},
|
|
|
|
{"Input Mux", "Mic_Line", "Input Mixer"},
|
|
|
|
{"Right Line", "Switch", "Input Mux"},
|
|
|
|
{"Left Line", "Switch", "Input Mux"},
|
|
|
|
{"LINE_IN", NULL, "Left Line"},
|
|
|
|
{"LINE_IN", NULL, "Right Line"},
|
|
|
|
};
|
|
|
|
|
2018-12-05 02:21:04 +08:00
|
|
|
static const unsigned int max9867_rates_44k1[] = {
|
|
|
|
11025, 22050, 44100,
|
2016-02-18 09:28:49 +08:00
|
|
|
};
|
|
|
|
|
2018-12-05 02:21:04 +08:00
|
|
|
static const struct snd_pcm_hw_constraint_list max9867_constraints_44k1 = {
|
|
|
|
.list = max9867_rates_44k1,
|
|
|
|
.count = ARRAY_SIZE(max9867_rates_44k1),
|
2016-02-18 09:28:49 +08:00
|
|
|
};
|
|
|
|
|
2018-12-05 02:21:04 +08:00
|
|
|
static const unsigned int max9867_rates_48k[] = {
|
|
|
|
8000, 16000, 32000, 48000,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_pcm_hw_constraint_list max9867_constraints_48k = {
|
|
|
|
.list = max9867_rates_48k,
|
|
|
|
.count = ARRAY_SIZE(max9867_rates_48k),
|
|
|
|
};
|
|
|
|
|
|
|
|
struct max9867_priv {
|
|
|
|
struct regmap *regmap;
|
|
|
|
const struct snd_pcm_hw_constraint_list *constraints;
|
|
|
|
unsigned int sysclk, pclk;
|
|
|
|
bool master, dsp_a;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int max9867_startup(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
2016-02-18 09:28:49 +08:00
|
|
|
{
|
2018-12-05 02:21:04 +08:00
|
|
|
struct max9867_priv *max9867 =
|
|
|
|
snd_soc_component_get_drvdata(dai->component);
|
2016-02-18 09:28:49 +08:00
|
|
|
|
2018-12-05 02:21:04 +08:00
|
|
|
if (max9867->constraints)
|
|
|
|
snd_pcm_hw_constraint_list(substream->runtime, 0,
|
|
|
|
SNDRV_PCM_HW_PARAM_RATE, max9867->constraints);
|
2016-02-18 09:28:49 +08:00
|
|
|
|
2018-12-05 02:21:04 +08:00
|
|
|
return 0;
|
2016-02-18 09:28:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int max9867_dai_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
|
|
|
|
{
|
2018-12-05 02:21:04 +08:00
|
|
|
int value;
|
|
|
|
unsigned long int rate, ratio;
|
2018-01-29 11:11:46 +08:00
|
|
|
struct snd_soc_component *component = dai->component;
|
|
|
|
struct max9867_priv *max9867 = snd_soc_component_get_drvdata(component);
|
2018-12-05 02:21:04 +08:00
|
|
|
unsigned int ni = DIV_ROUND_CLOSEST_ULL(96ULL * 0x10000 * params_rate(params),
|
|
|
|
max9867->pclk);
|
2016-02-18 09:28:49 +08:00
|
|
|
|
|
|
|
/* set up the ni value */
|
|
|
|
regmap_update_bits(max9867->regmap, MAX9867_AUDIOCLKHIGH,
|
2018-12-05 02:21:04 +08:00
|
|
|
MAX9867_NI_HIGH_MASK, (0xFF00 & ni) >> 8);
|
2016-02-18 09:28:49 +08:00
|
|
|
regmap_update_bits(max9867->regmap, MAX9867_AUDIOCLKLOW,
|
2018-12-05 02:21:04 +08:00
|
|
|
MAX9867_NI_LOW_MASK, 0x00FF & ni);
|
|
|
|
if (max9867->master) {
|
|
|
|
if (max9867->dsp_a) {
|
|
|
|
value = MAX9867_IFC1B_48X;
|
|
|
|
} else {
|
|
|
|
rate = params_rate(params) * 2 * params_width(params);
|
|
|
|
ratio = max9867->pclk / rate;
|
|
|
|
switch (params_width(params)) {
|
2016-02-19 02:36:20 +08:00
|
|
|
case 8:
|
|
|
|
case 16:
|
2018-12-05 02:21:04 +08:00
|
|
|
switch (ratio) {
|
|
|
|
case 2:
|
|
|
|
value = MAX9867_IFC1B_PCLK_2;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
value = MAX9867_IFC1B_PCLK_4;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
value = MAX9867_IFC1B_PCLK_8;
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
value = MAX9867_IFC1B_PCLK_16;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
value = MAX9867_IFC1B_48X;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
value = MAX9867_IFC1B_64X;
|
2016-02-19 02:36:20 +08:00
|
|
|
break;
|
|
|
|
default:
|
2016-02-18 09:28:49 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
regmap_update_bits(max9867->regmap, MAX9867_IFC1B,
|
2018-12-05 02:21:04 +08:00
|
|
|
MAX9867_IFC1B_BCLK_MASK, value);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* digital pll locks on to any externally supplied LRCLK signal
|
|
|
|
* and also enable rapid lock mode.
|
|
|
|
*/
|
|
|
|
regmap_update_bits(max9867->regmap, MAX9867_AUDIOCLKLOW,
|
|
|
|
MAX9867_RAPID_LOCK, MAX9867_RAPID_LOCK);
|
|
|
|
regmap_update_bits(max9867->regmap, MAX9867_AUDIOCLKHIGH,
|
|
|
|
MAX9867_PLL, MAX9867_PLL);
|
2016-02-18 09:28:49 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int max9867_mute(struct snd_soc_dai *dai, int mute)
|
|
|
|
{
|
2018-01-29 11:11:46 +08:00
|
|
|
struct snd_soc_component *component = dai->component;
|
|
|
|
struct max9867_priv *max9867 = snd_soc_component_get_drvdata(component);
|
2016-02-18 09:28:49 +08:00
|
|
|
|
|
|
|
if (mute)
|
|
|
|
regmap_update_bits(max9867->regmap, MAX9867_DACLEVEL,
|
|
|
|
MAX9867_DAC_MUTE_MASK, MAX9867_DAC_MUTE_MASK);
|
|
|
|
else
|
|
|
|
regmap_update_bits(max9867->regmap, MAX9867_DACLEVEL,
|
|
|
|
MAX9867_DAC_MUTE_MASK, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int max9867_set_dai_sysclk(struct snd_soc_dai *codec_dai,
|
|
|
|
int clk_id, unsigned int freq, int dir)
|
|
|
|
{
|
2018-01-29 11:11:46 +08:00
|
|
|
struct snd_soc_component *component = codec_dai->component;
|
|
|
|
struct max9867_priv *max9867 = snd_soc_component_get_drvdata(component);
|
2016-02-18 09:28:49 +08:00
|
|
|
int value = 0;
|
|
|
|
|
|
|
|
/* Set the prescaler based on the master clock frequency*/
|
|
|
|
if (freq >= 10000000 && freq <= 20000000) {
|
|
|
|
value |= MAX9867_PSCLK_10_20;
|
2018-11-23 22:27:00 +08:00
|
|
|
max9867->pclk = freq;
|
2016-02-18 09:28:49 +08:00
|
|
|
} else if (freq >= 20000000 && freq <= 40000000) {
|
|
|
|
value |= MAX9867_PSCLK_20_40;
|
2018-11-23 22:27:00 +08:00
|
|
|
max9867->pclk = freq / 2;
|
2016-02-18 09:28:49 +08:00
|
|
|
} else if (freq >= 40000000 && freq <= 60000000) {
|
|
|
|
value |= MAX9867_PSCLK_40_60;
|
2018-11-23 22:27:00 +08:00
|
|
|
max9867->pclk = freq / 4;
|
2016-02-18 09:28:49 +08:00
|
|
|
} else {
|
2018-03-01 22:19:53 +08:00
|
|
|
dev_err(component->dev,
|
|
|
|
"Invalid clock frequency %uHz (required 10-60MHz)\n",
|
|
|
|
freq);
|
2016-02-18 09:28:49 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-12-05 02:21:04 +08:00
|
|
|
if (freq % 48000 == 0)
|
|
|
|
max9867->constraints = &max9867_constraints_48k;
|
|
|
|
else if (freq % 44100 == 0)
|
|
|
|
max9867->constraints = &max9867_constraints_44k1;
|
|
|
|
else
|
|
|
|
dev_warn(component->dev,
|
|
|
|
"Unable to set exact rate with %uHz clock frequency\n",
|
|
|
|
freq);
|
2016-02-18 09:28:49 +08:00
|
|
|
max9867->sysclk = freq;
|
2018-12-05 02:21:04 +08:00
|
|
|
value = value << MAX9867_PSCLK_SHIFT;
|
2016-02-18 09:28:49 +08:00
|
|
|
/* exact integer mode is not supported */
|
|
|
|
value &= ~MAX9867_FREQ_MASK;
|
|
|
|
regmap_update_bits(max9867->regmap, MAX9867_SYSCLK,
|
|
|
|
MAX9867_PSCLK_MASK, value);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int max9867_dai_set_fmt(struct snd_soc_dai *codec_dai,
|
|
|
|
unsigned int fmt)
|
|
|
|
{
|
2018-01-29 11:11:46 +08:00
|
|
|
struct snd_soc_component *component = codec_dai->component;
|
|
|
|
struct max9867_priv *max9867 = snd_soc_component_get_drvdata(component);
|
2018-12-05 02:21:04 +08:00
|
|
|
u8 iface1A, iface1B;
|
2016-02-18 09:28:49 +08:00
|
|
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
2018-12-05 02:21:04 +08:00
|
|
|
max9867->master = true;
|
|
|
|
iface1A = MAX9867_MASTER;
|
|
|
|
iface1B = MAX9867_IFC1B_48X;
|
2016-02-18 09:28:49 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
2018-12-05 02:21:04 +08:00
|
|
|
max9867->master = false;
|
|
|
|
iface1A = iface1B = 0;
|
2016-02-18 09:28:49 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-03-01 22:21:30 +08:00
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
2018-12-05 02:21:04 +08:00
|
|
|
max9867->dsp_a = false;
|
2018-03-01 22:21:30 +08:00
|
|
|
iface1A |= MAX9867_I2S_DLY;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_DSP_A:
|
2018-12-05 02:21:04 +08:00
|
|
|
max9867->dsp_a = true;
|
2018-03-01 22:21:30 +08:00
|
|
|
iface1A |= MAX9867_TDM_MODE | MAX9867_SDOUT_HIZ;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2016-02-18 09:28:49 +08:00
|
|
|
|
|
|
|
/* Clock inversion bits, BCI and WCI */
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_NB_NF:
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_IF:
|
|
|
|
iface1A |= MAX9867_WCI_MODE | MAX9867_BCI_MODE;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_NF:
|
|
|
|
iface1A |= MAX9867_BCI_MODE;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_NB_IF:
|
|
|
|
iface1A |= MAX9867_WCI_MODE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-12-09 01:31:32 +08:00
|
|
|
regmap_write(max9867->regmap, MAX9867_IFC1A, iface1A);
|
|
|
|
regmap_write(max9867->regmap, MAX9867_IFC1B, iface1B);
|
2018-12-05 02:21:04 +08:00
|
|
|
|
2016-02-18 09:28:49 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-18 20:05:59 +08:00
|
|
|
static const struct snd_soc_dai_ops max9867_dai_ops = {
|
2016-02-18 09:28:49 +08:00
|
|
|
.set_sysclk = max9867_set_dai_sysclk,
|
2018-12-05 02:21:04 +08:00
|
|
|
.set_fmt = max9867_dai_set_fmt,
|
2016-02-18 09:28:49 +08:00
|
|
|
.digital_mute = max9867_mute,
|
2018-12-05 02:21:04 +08:00
|
|
|
.startup = max9867_startup,
|
|
|
|
.hw_params = max9867_dai_hw_params,
|
2016-02-18 09:28:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct snd_soc_dai_driver max9867_dai[] = {
|
|
|
|
{
|
|
|
|
.name = "max9867-aif1",
|
|
|
|
.playback = {
|
|
|
|
.stream_name = "HiFi Playback",
|
2018-03-01 22:20:56 +08:00
|
|
|
.channels_min = 2,
|
2016-02-18 09:28:49 +08:00
|
|
|
.channels_max = 2,
|
2018-12-05 02:21:04 +08:00
|
|
|
.rates = SNDRV_PCM_RATE_8000_48000,
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
2016-02-18 09:28:49 +08:00
|
|
|
},
|
|
|
|
.capture = {
|
|
|
|
.stream_name = "HiFi Capture",
|
2018-03-01 22:20:56 +08:00
|
|
|
.channels_min = 2,
|
2016-02-18 09:28:49 +08:00
|
|
|
.channels_max = 2,
|
2018-12-05 02:21:04 +08:00
|
|
|
.rates = SNDRV_PCM_RATE_8000_48000,
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
2016-02-18 09:28:49 +08:00
|
|
|
},
|
|
|
|
.ops = &max9867_dai_ops,
|
2018-03-01 22:20:56 +08:00
|
|
|
.symmetric_rates = 1,
|
2016-02-18 09:28:49 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-05 02:19:51 +08:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int max9867_suspend(struct snd_soc_component *component)
|
2016-02-18 09:28:49 +08:00
|
|
|
{
|
2018-12-05 02:19:51 +08:00
|
|
|
snd_soc_component_force_bias_level(component, SND_SOC_BIAS_OFF);
|
2016-02-18 09:28:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-05 02:19:51 +08:00
|
|
|
static int max9867_resume(struct snd_soc_component *component)
|
2016-02-18 09:28:49 +08:00
|
|
|
{
|
2018-12-05 02:19:51 +08:00
|
|
|
snd_soc_component_force_bias_level(component, SND_SOC_BIAS_STANDBY);
|
2016-02-18 09:28:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-12-05 02:19:51 +08:00
|
|
|
#else
|
|
|
|
#define max9867_suspend NULL
|
|
|
|
#define max9867_resume NULL
|
2016-02-18 09:28:49 +08:00
|
|
|
#endif
|
|
|
|
|
2018-12-05 02:19:51 +08:00
|
|
|
static int max9867_set_bias_level(struct snd_soc_component *component,
|
|
|
|
enum snd_soc_bias_level level)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct max9867_priv *max9867 = snd_soc_component_get_drvdata(component);
|
|
|
|
|
|
|
|
switch (level) {
|
|
|
|
case SND_SOC_BIAS_STANDBY:
|
|
|
|
if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) {
|
|
|
|
err = regcache_sync(max9867->regmap);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = regmap_update_bits(max9867->regmap, MAX9867_PWRMAN,
|
|
|
|
MAX9867_SHTDOWN, MAX9867_SHTDOWN);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SND_SOC_BIAS_OFF:
|
|
|
|
err = regmap_update_bits(max9867->regmap, MAX9867_PWRMAN,
|
|
|
|
MAX9867_SHTDOWN, 0);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
regcache_mark_dirty(max9867->regmap);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-29 11:11:46 +08:00
|
|
|
static const struct snd_soc_component_driver max9867_component = {
|
|
|
|
.controls = max9867_snd_controls,
|
|
|
|
.num_controls = ARRAY_SIZE(max9867_snd_controls),
|
|
|
|
.dapm_routes = max9867_audio_map,
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(max9867_audio_map),
|
|
|
|
.dapm_widgets = max9867_dapm_widgets,
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(max9867_dapm_widgets),
|
2018-12-05 02:19:51 +08:00
|
|
|
.suspend = max9867_suspend,
|
|
|
|
.resume = max9867_resume,
|
|
|
|
.set_bias_level = max9867_set_bias_level,
|
2018-01-29 11:11:46 +08:00
|
|
|
.idle_bias_on = 1,
|
|
|
|
.use_pmdown_time = 1,
|
|
|
|
.endianness = 1,
|
|
|
|
.non_legacy_dai_naming = 1,
|
2016-02-18 09:28:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool max9867_volatile_register(struct device *dev, unsigned int reg)
|
|
|
|
{
|
|
|
|
switch (reg) {
|
|
|
|
case MAX9867_STATUS:
|
|
|
|
case MAX9867_JACKSTATUS:
|
|
|
|
case MAX9867_AUXHIGH:
|
|
|
|
case MAX9867_AUXLOW:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-20 10:54:11 +08:00
|
|
|
static const struct reg_default max9867_reg[] = {
|
2016-02-18 09:28:49 +08:00
|
|
|
{ 0x04, 0x00 },
|
|
|
|
{ 0x05, 0x00 },
|
|
|
|
{ 0x06, 0x00 },
|
|
|
|
{ 0x07, 0x00 },
|
|
|
|
{ 0x08, 0x00 },
|
|
|
|
{ 0x09, 0x00 },
|
|
|
|
{ 0x0A, 0x00 },
|
|
|
|
{ 0x0B, 0x00 },
|
|
|
|
{ 0x0C, 0x00 },
|
|
|
|
{ 0x0D, 0x00 },
|
|
|
|
{ 0x0E, 0x00 },
|
|
|
|
{ 0x0F, 0x00 },
|
|
|
|
{ 0x10, 0x00 },
|
|
|
|
{ 0x11, 0x00 },
|
|
|
|
{ 0x12, 0x00 },
|
|
|
|
{ 0x13, 0x00 },
|
|
|
|
{ 0x14, 0x00 },
|
|
|
|
{ 0x15, 0x00 },
|
|
|
|
{ 0x16, 0x00 },
|
|
|
|
{ 0x17, 0x00 },
|
|
|
|
};
|
|
|
|
|
2016-02-20 10:54:11 +08:00
|
|
|
static const struct regmap_config max9867_regmap = {
|
2016-02-18 09:28:49 +08:00
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
.max_register = MAX9867_REVISION,
|
|
|
|
.reg_defaults = max9867_reg,
|
|
|
|
.num_reg_defaults = ARRAY_SIZE(max9867_reg),
|
|
|
|
.volatile_reg = max9867_volatile_register,
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int max9867_i2c_probe(struct i2c_client *i2c,
|
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
|
|
|
struct max9867_priv *max9867;
|
2018-12-05 02:18:17 +08:00
|
|
|
int ret, reg;
|
2016-02-18 09:28:49 +08:00
|
|
|
|
2018-11-23 22:27:00 +08:00
|
|
|
max9867 = devm_kzalloc(&i2c->dev, sizeof(*max9867), GFP_KERNEL);
|
2016-02-18 09:28:49 +08:00
|
|
|
if (!max9867)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
i2c_set_clientdata(i2c, max9867);
|
|
|
|
max9867->regmap = devm_regmap_init_i2c(i2c, &max9867_regmap);
|
|
|
|
if (IS_ERR(max9867->regmap)) {
|
|
|
|
ret = PTR_ERR(max9867->regmap);
|
2018-03-01 22:19:53 +08:00
|
|
|
dev_err(&i2c->dev, "Failed to allocate regmap: %d\n", ret);
|
2016-02-18 09:28:49 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2018-11-23 22:27:00 +08:00
|
|
|
ret = regmap_read(max9867->regmap, MAX9867_REVISION, ®);
|
2016-02-18 09:28:49 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&i2c->dev, "Failed to read: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
dev_info(&i2c->dev, "device revision: %x\n", reg);
|
2018-01-29 11:11:46 +08:00
|
|
|
ret = devm_snd_soc_register_component(&i2c->dev, &max9867_component,
|
2016-02-18 09:28:49 +08:00
|
|
|
max9867_dai, ARRAY_SIZE(max9867_dai));
|
2018-12-05 02:18:17 +08:00
|
|
|
if (ret < 0)
|
2018-01-29 11:11:46 +08:00
|
|
|
dev_err(&i2c->dev, "Failed to register component: %d\n", ret);
|
2016-02-18 09:28:49 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct i2c_device_id max9867_i2c_id[] = {
|
|
|
|
{ "max9867", 0 },
|
2016-02-20 10:53:15 +08:00
|
|
|
{ }
|
2016-02-18 09:28:49 +08:00
|
|
|
};
|
2017-04-05 01:19:39 +08:00
|
|
|
MODULE_DEVICE_TABLE(i2c, max9867_i2c_id);
|
2016-02-18 09:28:49 +08:00
|
|
|
|
|
|
|
static const struct of_device_id max9867_of_match[] = {
|
|
|
|
{ .compatible = "maxim,max9867", },
|
|
|
|
{ }
|
|
|
|
};
|
2017-04-05 01:19:39 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, max9867_of_match);
|
2016-02-18 09:28:49 +08:00
|
|
|
|
|
|
|
static struct i2c_driver max9867_i2c_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "max9867",
|
|
|
|
.of_match_table = of_match_ptr(max9867_of_match),
|
|
|
|
},
|
|
|
|
.probe = max9867_i2c_probe,
|
|
|
|
.id_table = max9867_i2c_id,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_i2c_driver(max9867_i2c_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("anish kumar <yesanishhere@gmail.com>");
|
|
|
|
MODULE_DESCRIPTION("ALSA SoC MAX9867 driver");
|
|
|
|
MODULE_LICENSE("GPL");
|