18 #include <linux/module.h>
23 #include <linux/i2c.h>
24 #include <linux/slab.h>
34 #define DVOL_CTL_DVMUTE_ON BIT(4)
35 #define DVOL_CTL_DVMUTE_OFF 0
36 #define ML26124_SAI_NO_DELAY BIT(1)
37 #define ML26124_SAI_FRAME_SYNC (BIT(5) | BIT(0))
38 #define ML26134_CACHESIZE 212
39 #define ML26124_VMID BIT(1)
40 #define ML26124_RATES (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_32000 |\
42 #define ML26124_FORMATS (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |\
43 SNDRV_PCM_FMTBIT_S32_LE)
44 #define ML26124_NUM_REGISTER ML26134_CACHESIZE
73 static const char *
const ml26124_companding[] = {
"16bit PCM",
"u-law",
76 static const struct soc_enum ml26124_adc_companding_enum
79 static const struct soc_enum ml26124_dac_companding_enum
84 0xff, 1, digital_tlv),
86 0xff, 1, digital_tlv),
90 0xff, 1, digital_tlv),
92 0xff, 1, digital_tlv),
94 0xff, 1, digital_tlv),
96 0xff, 1, digital_tlv),
98 0xff, 1, digital_tlv),
124 SOC_ENUM(
"DAC Companding", ml26124_dac_companding_enum),
125 SOC_ENUM(
"ADC Companding", ml26124_adc_companding_enum),
136 static const char *
const ml26124_input_select[] = {
"Analog MIC SingleEnded in",
137 "Digital MIC in",
"Analog MIC Differential in"};
139 static const struct soc_enum ml26124_insel_enum =
154 &ml26124_output_mixer_controls[0],
160 &ml26124_input_mux_controls),
162 &ml26124_line_control),
172 {
"DAC",
NULL,
"MCLKEN"},
173 {
"ADC",
NULL,
"MCLKEN"},
174 {
"DAC",
NULL,
"PLLEN"},
175 {
"ADC",
NULL,
"PLLEN"},
176 {
"DAC",
NULL,
"PLLOE"},
177 {
"ADC",
NULL,
"PLLOE"},
180 {
"Output Mixer",
"DAC Switch",
"DAC"},
181 {
"Output Mixer",
"Line in loopback Switch",
"LIN"},
184 {
"LOUT",
NULL,
"Output Mixer"},
185 {
"SPOUT",
NULL,
"Output Mixer"},
186 {
"Line Out Enable",
NULL,
"LOUT"},
189 {
"ADC",
NULL,
"Input Mux"},
190 {
"Input Mux",
"Analog MIC SingleEnded in",
"PGA"},
191 {
"Input Mux",
"Analog MIC Differential in",
"PGA"},
192 {
"PGA",
NULL,
"MIN"},
196 static const struct clk_coeff coeff_div[] = {
197 {12288000, 16000, 0xc, 0x0, 0x20, 0x0, 0x4},
198 {12288000, 32000, 0xc, 0x0, 0x20, 0x0, 0x4},
199 {12288000, 48000, 0xc, 0x0, 0x30, 0x0, 0x4},
306 static inline int get_srate(
int rate)
326 static inline int get_coeff(
int mclk,
int rate)
331 if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
384 coeff_div[i].plldiv);
398 coeff_div[i].plldiv);
412 coeff_div[i].plldiv);
415 pr_err(
"%s:this rate is no support for ml26124\n", __func__);
425 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
446 static int ml26124_set_dai_fmt(
struct snd_soc_dai *codec_dai,
484 static int ml26124_set_dai_sysclk(
struct snd_soc_dai *codec_dai,
485 int clk_id,
unsigned int freq,
int dir)
488 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
506 static int ml26124_set_bias_level(
struct snd_soc_codec *codec,
509 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
542 .hw_params = ml26124_hw_params,
543 .digital_mute = ml26124_mute,
544 .set_fmt = ml26124_set_dai_fmt,
545 .set_sysclk = ml26124_set_dai_sysclk,
549 .name =
"ml26124-hifi",
551 .stream_name =
"Playback",
557 .stream_name =
"Capture",
562 .ops = &ml26124_dai_ops,
563 .symmetric_rates = 1,
581 #define ml26124_suspend NULL
582 #define ml26124_resume NULL
588 struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
593 dev_err(codec->
dev,
"Failed to set cache I/O: %d\n", ret);
607 .probe = ml26124_probe,
610 .set_bias_level = ml26124_set_bias_level,
611 .dapm_widgets = ml26124_dapm_widgets,
612 .num_dapm_widgets =
ARRAY_SIZE(ml26124_dapm_widgets),
613 .dapm_routes = ml26124_intercon,
614 .num_dapm_routes =
ARRAY_SIZE(ml26124_intercon),
615 .controls = ml26124_snd_controls,
616 .num_controls =
ARRAY_SIZE(ml26124_snd_controls),
619 static const struct regmap_config ml26124_i2c_regmap = {
623 .reg_defaults = ml26124_reg,
626 .write_flag_mask = 0x01,
639 i2c_set_clientdata(i2c, priv);
642 if (IS_ERR(priv->
regmap)) {
643 ret = PTR_ERR(priv->
regmap);
644 dev_err(&i2c->
dev,
"regmap_init_i2c() failed: %d\n", ret);
649 &soc_codec_dev_ml26124, &ml26124_dai, 1);
664 static struct i2c_driver ml26124_i2c_driver = {
669 .probe = ml26124_i2c_probe,
671 .id_table = ml26124_i2c_id,