2018-01-12 09:37:28 +01:00
|
|
|
/*
|
2018-01-22 04:20:17 +01:00
|
|
|
* ac101.c
|
|
|
|
* (C) Copyright 2017-2018
|
|
|
|
* Seeed Technology Co., Ltd. <www.seeedstudio.com>
|
|
|
|
*
|
|
|
|
* PeterYang <linsheng.yang@seeed.cc>
|
|
|
|
*
|
2018-01-12 09:37:28 +01:00
|
|
|
* (C) Copyright 2014-2017
|
|
|
|
* Reuuimlla Technology Co., Ltd. <www.reuuimllatech.com>
|
|
|
|
*
|
|
|
|
* huangxin <huangxin@Reuuimllatech.com>
|
|
|
|
* liushaohua <liushaohua@allwinnertech.com>
|
|
|
|
*
|
2018-01-22 04:20:17 +01:00
|
|
|
* X-Powers AC101 codec driver
|
2018-01-12 09:37:28 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
*/
|
2018-02-10 08:16:01 +01:00
|
|
|
#undef AC101_DEBG
|
2018-01-12 09:37:28 +01:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/soc-dapm.h>
|
|
|
|
#include <sound/tlv.h>
|
|
|
|
#include <linux/i2c.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/clk.h>
|
2018-01-26 04:08:09 +01:00
|
|
|
#include <linux/gpio/consumer.h>
|
2018-01-19 12:25:15 +01:00
|
|
|
#include <linux/regmap.h>
|
2018-02-10 08:16:01 +01:00
|
|
|
#include "ac101_regs.h"
|
|
|
|
#include "ac10x.h"
|
2018-01-12 09:37:28 +01:00
|
|
|
|
|
|
|
/*Default initialize configuration*/
|
2018-02-07 10:35:12 +01:00
|
|
|
static bool speaker_double_used = 1;
|
|
|
|
static int double_speaker_val = 0x1B;
|
|
|
|
static int single_speaker_val = 0x19;
|
|
|
|
static int headset_val = 0x3B;
|
|
|
|
static int mainmic_val = 0x4;
|
|
|
|
static int headsetmic_val = 0x4;
|
|
|
|
static bool dmic_used = 0;
|
|
|
|
static int adc_digital_val = 0xb0b0;
|
|
|
|
static bool drc_used = false;
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
#define AC101_RATES (SNDRV_PCM_RATE_8000_96000 & \
|
2018-02-05 03:45:55 +01:00
|
|
|
~(SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_64000 | \
|
|
|
|
SNDRV_PCM_RATE_88200))
|
2018-02-10 08:16:01 +01:00
|
|
|
#define AC101_FORMATS (/*SNDRV_PCM_FMTBIT_S16_LE | \
|
2018-01-24 13:18:58 +01:00
|
|
|
SNDRV_PCM_FMTBIT_S24_LE |*/ \
|
|
|
|
SNDRV_PCM_FMTBIT_S32_LE | \
|
2018-01-19 12:25:15 +01:00
|
|
|
0)
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
static struct ac10x_priv* static_ac10x;
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_read(struct snd_soc_codec *codec, unsigned reg) {
|
|
|
|
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
|
|
|
int r, v = 0;
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
if ((r = regmap_read(ac10x->regmap101, reg, &v)) < 0) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
2018-01-26 04:08:09 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_write(struct snd_soc_codec *codec, unsigned reg, unsigned val) {
|
|
|
|
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
|
|
|
|
|
|
|
return regmap_write(ac10x->regmap101, reg, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ac101_update_bits(struct snd_soc_codec *codec, unsigned reg,
|
|
|
|
unsigned mask, unsigned value
|
|
|
|
) {
|
|
|
|
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
|
|
|
|
|
|
|
return regmap_update_bits(ac10x->regmap101, reg, mask, value);
|
|
|
|
}
|
2018-01-12 09:37:28 +01:00
|
|
|
|
|
|
|
void drc_config(struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
int reg_val;
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, 0xa3);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x7ff<<0);
|
|
|
|
reg_val |= 1<<0;
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xa3, reg_val);
|
|
|
|
ac101_write(codec, 0xa4, 0x2baf);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, 0xa5);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x7ff<<0);
|
|
|
|
reg_val |= 1<<0;
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xa5, reg_val);
|
|
|
|
ac101_write(codec, 0xa6, 0x2baf);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, 0xa7);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x7ff<<0);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xa7, reg_val);
|
|
|
|
ac101_write(codec, 0xa8, 0x44a);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, 0xa9);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x7ff<<0);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xa9, reg_val);
|
|
|
|
ac101_write(codec, 0xaa, 0x1e06);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, 0xab);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x7ff<<0);
|
|
|
|
reg_val |= (0x352<<0);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xab, reg_val);
|
|
|
|
ac101_write(codec, 0xac, 0x6910);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, 0xad);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x7ff<<0);
|
|
|
|
reg_val |= (0x77a<<0);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xad, reg_val);
|
|
|
|
ac101_write(codec, 0xae, 0xaaaa);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, 0xaf);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x7ff<<0);
|
|
|
|
reg_val |= (0x2de<<0);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xaf, reg_val);
|
|
|
|
ac101_write(codec, 0xb0, 0xc982);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0x16, 0x9f9f);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
void drc_enable(struct snd_soc_codec *codec,bool on)
|
|
|
|
{
|
|
|
|
int reg_val;
|
|
|
|
if (on) {
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xb5, 0xA080);
|
|
|
|
reg_val = ac101_read(codec, MOD_CLK_ENA);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val |= (0x1<<6);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, MOD_CLK_ENA, reg_val);
|
|
|
|
reg_val = ac101_read(codec, MOD_RST_CTRL);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val |= (0x1<<6);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, MOD_RST_CTRL, reg_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, 0xa0);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val |= (0x7<<0);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xa0, reg_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
} else {
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xb5, 0x0);
|
|
|
|
reg_val = ac101_read(codec, MOD_CLK_ENA);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x1<<6);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, MOD_CLK_ENA, reg_val);
|
|
|
|
reg_val = ac101_read(codec, MOD_RST_CTRL);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x1<<6);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, MOD_RST_CTRL, reg_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, 0xa0);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x7<<0);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, 0xa0, reg_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
void set_configuration(struct snd_soc_codec *codec)
|
|
|
|
{
|
|
|
|
if (speaker_double_used) {
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, SPKOUT_CTRL, (0x1f<<SPK_VOL), (double_speaker_val<<SPK_VOL));
|
2018-01-12 09:37:28 +01:00
|
|
|
} else {
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, SPKOUT_CTRL, (0x1f<<SPK_VOL), (single_speaker_val<<SPK_VOL));
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, HPOUT_CTRL, (0x3f<<HP_VOL), (headset_val<<HP_VOL));
|
|
|
|
ac101_update_bits(codec, ADC_SRCBST_CTRL, (0x7<<ADC_MIC1G), (mainmic_val<<ADC_MIC1G));
|
|
|
|
ac101_update_bits(codec, ADC_SRCBST_CTRL, (0x7<<ADC_MIC2G), (headsetmic_val<<ADC_MIC2G));
|
2018-01-12 09:37:28 +01:00
|
|
|
if (dmic_used) {
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, ADC_VOL_CTRL, adc_digital_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
if (drc_used) {
|
|
|
|
drc_config(codec);
|
|
|
|
}
|
|
|
|
/*headphone calibration clock frequency select*/
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, SPKOUT_CTRL, (0x7<<HPCALICKS), (0x7<<HPCALICKS));
|
2018-01-23 09:19:00 +01:00
|
|
|
|
|
|
|
/* I2S1 DAC Timeslot 0 data <- I2S1 DAC channel 0 */
|
|
|
|
// "AIF1IN0L Mux" <= "AIF1DACL"
|
|
|
|
// "AIF1IN0R Mux" <= "AIF1DACR"
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, AIF1_DACDAT_CTRL, 0x3 << AIF1_DA0L_SRC, 0x0 << AIF1_DA0L_SRC);
|
|
|
|
ac101_update_bits(codec, AIF1_DACDAT_CTRL, 0x3 << AIF1_DA0R_SRC, 0x0 << AIF1_DA0R_SRC);
|
2018-01-23 09:19:00 +01:00
|
|
|
/* Timeslot 0 Left & Right Channel enable */
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, AIF1_DACDAT_CTRL, 0x3 << AIF1_DA0R_ENA, 0x3 << AIF1_DA0R_ENA);
|
2018-01-23 09:19:00 +01:00
|
|
|
|
|
|
|
/* DAC Digital Mixer Source Select <- I2S1 DA0 */
|
|
|
|
// "DACL Mixer" += "AIF1IN0L Mux"
|
|
|
|
// "DACR Mixer" += "AIF1IN0R Mux"
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, DAC_MXR_SRC, 0xF << DACL_MXR_ADCL, 0x8 << DACL_MXR_ADCL);
|
|
|
|
ac101_update_bits(codec, DAC_MXR_SRC, 0xF << DACR_MXR_ADCR, 0x8 << DACR_MXR_ADCR);
|
2018-01-23 09:19:00 +01:00
|
|
|
/* Internal DAC Analog Left & Right Channel enable */
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, OMIXER_DACA_CTRL, 0x3 << DACALEN, 0x3 << DACALEN);
|
2018-01-23 09:19:00 +01:00
|
|
|
|
|
|
|
/* Output Mixer Source Select */
|
|
|
|
// "Left Output Mixer" += "DACL Mixer"
|
|
|
|
// "Right Output Mixer" += "DACR Mixer"
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, OMIXER_SR, 0x1 << LMIXMUTEDACL, 0x1 << LMIXMUTEDACL);
|
|
|
|
ac101_update_bits(codec, OMIXER_SR, 0x1 << RMIXMUTEDACR, 0x1 << RMIXMUTEDACR);
|
2018-01-23 09:19:00 +01:00
|
|
|
/* Left & Right Analog Output Mixer enable */
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, OMIXER_DACA_CTRL, 0x3 << LMIXEN, 0x3 << LMIXEN);
|
2018-01-23 09:19:00 +01:00
|
|
|
|
|
|
|
/* Headphone Ouput Control */
|
|
|
|
// "HP_R Mux" <= "DACR Mixer"
|
|
|
|
// "HP_L Mux" <= "DACL Mixer"
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, HPOUT_CTRL, 0x1 << LHPS, 0x0 << LHPS);
|
|
|
|
ac101_update_bits(codec, HPOUT_CTRL, 0x1 << RHPS, 0x0 << RHPS);
|
2018-01-23 09:19:00 +01:00
|
|
|
|
|
|
|
/* Speaker Output Control */
|
|
|
|
// "SPK_L Mux" <= "SPK_LR Adder"
|
|
|
|
// "SPK_R Mux" <= "SPK_LR Adder"
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, SPKOUT_CTRL, (0x1 << LSPKS) | (0x1 << RSPKS), (0x1 << LSPKS) | (0x1 << RSPKS));
|
2018-01-23 09:19:00 +01:00
|
|
|
/* Enable Left & Right Speaker */
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, SPKOUT_CTRL, (0x1 << LSPK_EN) | (0x1 << RSPK_EN), (0x1 << LSPK_EN) | (0x1 << RSPK_EN));
|
|
|
|
return;
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
2018-01-22 04:20:17 +01:00
|
|
|
|
2018-01-23 09:19:00 +01:00
|
|
|
static int late_enable_dac(struct snd_soc_codec* codec, int event) {
|
2018-01-12 09:37:28 +01:00
|
|
|
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
|
|
|
mutex_lock(&ac10x->dac_mutex);
|
|
|
|
switch (event) {
|
|
|
|
case SND_SOC_DAPM_PRE_PMU:
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("%s,line:%d\n",__func__,__LINE__);
|
2018-01-12 09:37:28 +01:00
|
|
|
if (ac10x->dac_enable == 0){
|
|
|
|
/*enable dac module clk*/
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_DAC_DIG), (0x1<<MOD_CLK_DAC_DIG));
|
|
|
|
ac101_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_DAC_DIG), (0x1<<MOD_RESET_DAC_DIG));
|
|
|
|
ac101_update_bits(codec, DAC_DIG_CTRL, (0x1<<ENDA), (0x1<<ENDA));
|
|
|
|
ac101_update_bits(codec, DAC_DIG_CTRL, (0x1<<ENHPF),(0x1<<ENHPF));
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
ac10x->dac_enable++;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAPM_POST_PMD:
|
2018-01-30 12:12:47 +01:00
|
|
|
#if 0
|
2018-01-12 09:37:28 +01:00
|
|
|
if (ac10x->dac_enable > 0){
|
|
|
|
ac10x->dac_enable--;
|
2018-01-30 12:12:47 +01:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
if (ac10x->dac_enable != 0){
|
|
|
|
ac10x->dac_enable = 0;
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, DAC_DIG_CTRL, (0x1<<ENHPF),(0x0<<ENHPF));
|
|
|
|
ac101_update_bits(codec, DAC_DIG_CTRL, (0x1<<ENDA), (0x0<<ENDA));
|
2018-01-12 09:37:28 +01:00
|
|
|
/*disable dac module clk*/
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_DAC_DIG), (0x0<<MOD_CLK_DAC_DIG));
|
|
|
|
ac101_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_DAC_DIG), (0x0<<MOD_RESET_DAC_DIG));
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&ac10x->dac_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
static int ac101_headphone_event(struct snd_soc_codec* codec, int event) {
|
2018-01-12 09:37:28 +01:00
|
|
|
switch (event) {
|
|
|
|
case SND_SOC_DAPM_POST_PMU:
|
|
|
|
/*open*/
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("post:open:%s,line:%d\n", __func__, __LINE__);
|
|
|
|
ac101_update_bits(codec, OMIXER_DACA_CTRL, (0xf<<HPOUTPUTENABLE), (0xf<<HPOUTPUTENABLE));
|
|
|
|
ac101_update_bits(codec, HPOUT_CTRL, (0x1<<HPPA_EN), (0x1<<HPPA_EN));
|
2018-01-12 09:37:28 +01:00
|
|
|
msleep(10);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, HPOUT_CTRL, (0x3<<LHPPA_MUTE), (0x3<<LHPPA_MUTE));
|
2018-01-12 09:37:28 +01:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAPM_PRE_PMD:
|
|
|
|
/*close*/
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("pre:close:%s,line:%d\n", __func__, __LINE__);
|
|
|
|
ac101_update_bits(codec, HPOUT_CTRL, (0x1<<HPPA_EN), (0x0<<HPPA_EN));
|
|
|
|
ac101_update_bits(codec, OMIXER_DACA_CTRL, (0xf<<HPOUTPUTENABLE), (0x0<<HPOUTPUTENABLE));
|
|
|
|
ac101_update_bits(codec, HPOUT_CTRL, (0x3<<LHPPA_MUTE), (0x0<<LHPPA_MUTE));
|
2018-01-12 09:37:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
static int ac101_aif1clk(struct snd_soc_codec* codec, int event) {
|
2018-01-12 09:37:28 +01:00
|
|
|
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("%s() L%d event=%d pre_up/%d post_down/%d\n", __func__, __LINE__,
|
2018-01-19 12:25:15 +01:00
|
|
|
event, SND_SOC_DAPM_PRE_PMU, SND_SOC_DAPM_POST_PMD);
|
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
mutex_lock(&ac10x->aifclk_mutex);
|
|
|
|
switch (event) {
|
|
|
|
case SND_SOC_DAPM_PRE_PMU:
|
|
|
|
if (ac10x->aif1_clken == 0){
|
|
|
|
/*enable AIF1CLK*/
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, SYSCLK_CTRL, (0x1<<AIF1CLK_ENA), (0x1<<AIF1CLK_ENA));
|
|
|
|
ac101_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_AIF1), (0x1<<MOD_CLK_AIF1));
|
|
|
|
ac101_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_AIF1), (0x1<<MOD_RESET_AIF1));
|
2018-01-12 09:37:28 +01:00
|
|
|
/*enable systemclk*/
|
2018-01-23 09:19:00 +01:00
|
|
|
if (ac10x->aif2_clken == 0)
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, SYSCLK_CTRL, (0x1<<SYSCLK_ENA), (0x1<<SYSCLK_ENA));
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
ac10x->aif1_clken++;
|
|
|
|
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAPM_POST_PMD:
|
2018-01-30 12:12:47 +01:00
|
|
|
#if 0
|
2018-01-12 09:37:28 +01:00
|
|
|
if (ac10x->aif1_clken > 0){
|
|
|
|
ac10x->aif1_clken--;
|
|
|
|
if (ac10x->aif1_clken == 0){
|
2018-01-30 12:12:47 +01:00
|
|
|
#else
|
|
|
|
{
|
|
|
|
if (ac10x->aif1_clken != 0) {
|
|
|
|
ac10x->aif1_clken = 0;
|
|
|
|
#endif
|
2018-01-12 09:37:28 +01:00
|
|
|
/*disable AIF1CLK*/
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, SYSCLK_CTRL, (0x1<<AIF1CLK_ENA), (0x0<<AIF1CLK_ENA));
|
|
|
|
ac101_update_bits(codec, MOD_CLK_ENA, (0x1<<MOD_CLK_AIF1), (0x0<<MOD_CLK_AIF1));
|
|
|
|
ac101_update_bits(codec, MOD_RST_CTRL, (0x1<<MOD_RESET_AIF1), (0x0<<MOD_RESET_AIF1));
|
2018-01-12 09:37:28 +01:00
|
|
|
/*DISABLE systemclk*/
|
2018-01-23 09:19:00 +01:00
|
|
|
if (ac10x->aif2_clken == 0)
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, SYSCLK_CTRL, (0x1<<SYSCLK_ENA), (0x0<<SYSCLK_ENA));
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&ac10x->aifclk_mutex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
/**
|
|
|
|
* snd_ac101_get_volsw - single mixer get callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @ucontrol: control element information
|
|
|
|
*
|
|
|
|
* Callback to get the value of a single mixer control, or a double mixer
|
|
|
|
* control that spans 2 registers.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
static int snd_ac101_get_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol
|
|
|
|
){
|
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
|
|
|
unsigned int val, mask = (1 << fls(mc->max)) - 1;
|
|
|
|
unsigned int invert = mc->invert;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((ret = ac101_read(static_ac10x->codec, mc->reg)) < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
val = (ret >> mc->shift) & mask;
|
|
|
|
ucontrol->value.integer.value[0] = val - mc->min;
|
|
|
|
if (invert) {
|
|
|
|
ucontrol->value.integer.value[0] =
|
|
|
|
mc->max - ucontrol->value.integer.value[0];
|
|
|
|
}
|
2018-02-27 03:58:10 +01:00
|
|
|
|
|
|
|
if (snd_soc_volsw_is_stereo(mc)) {
|
|
|
|
val = (ret >> mc->rshift) & mask;
|
|
|
|
ucontrol->value.integer.value[1] = val - mc->min;
|
|
|
|
if (invert) {
|
|
|
|
ucontrol->value.integer.value[1] =
|
|
|
|
mc->max - ucontrol->value.integer.value[1];
|
|
|
|
}
|
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_ac101_put_volsw - single mixer put callback
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @ucontrol: control element information
|
|
|
|
*
|
|
|
|
* Callback to set the value of a single mixer control, or a double mixer
|
|
|
|
* control that spans 2 registers.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
static int snd_ac101_put_volsw(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol
|
|
|
|
){
|
|
|
|
struct soc_mixer_control *mc =
|
|
|
|
(struct soc_mixer_control *)kcontrol->private_value;
|
|
|
|
unsigned int sign_bit = mc->sign_bit;
|
|
|
|
unsigned int val, mask = (1 << fls(mc->max)) - 1;
|
|
|
|
unsigned int invert = mc->invert;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (sign_bit)
|
|
|
|
mask = BIT(sign_bit + 1) - 1;
|
|
|
|
|
|
|
|
val = ((ucontrol->value.integer.value[0] + mc->min) & mask);
|
|
|
|
if (invert) {
|
|
|
|
val = mc->max - val;
|
|
|
|
}
|
|
|
|
|
2018-02-27 03:58:10 +01:00
|
|
|
ret = ac101_update_bits(static_ac10x->codec, mc->reg, mask << mc->shift, val << mc->shift);
|
|
|
|
|
|
|
|
if (! snd_soc_volsw_is_stereo(mc)) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
val = ((ucontrol->value.integer.value[1] + mc->min) & mask);
|
|
|
|
if (invert) {
|
|
|
|
val = mc->max - val;
|
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
|
2018-02-27 03:58:10 +01:00
|
|
|
ret = ac101_update_bits(static_ac10x->codec, mc->reg, mask << mc->rshift, val << mc->rshift);
|
2018-02-10 08:16:01 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -11925, 75, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(dac_mix_vol_tlv, -600, 600, 0);
|
2018-02-07 10:35:12 +01:00
|
|
|
static const DECLARE_TLV_DB_SCALE(dig_vol_tlv, -7308, 116, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(speaker_vol_tlv, -4800, 150, 0);
|
|
|
|
static const DECLARE_TLV_DB_SCALE(headphone_vol_tlv, -6300, 100, 0);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
static struct snd_kcontrol_new ac101_controls[] = {
|
2018-01-12 09:37:28 +01:00
|
|
|
/*DAC*/
|
|
|
|
SOC_DOUBLE_TLV("DAC volume", DAC_VOL_CTRL, DAC_VOL_L, DAC_VOL_R, 0xff, 0, dac_vol_tlv),
|
|
|
|
SOC_DOUBLE_TLV("DAC mixer gain", DAC_MXR_GAIN, DACL_MXR_GAIN, DACR_MXR_GAIN, 0xf, 0, dac_mix_vol_tlv),
|
2018-01-23 09:19:00 +01:00
|
|
|
SOC_SINGLE_TLV("digital volume", DAC_DBG_CTRL, DVC, 0x3f, 1, dig_vol_tlv),
|
2018-01-12 09:37:28 +01:00
|
|
|
SOC_SINGLE_TLV("speaker volume", SPKOUT_CTRL, SPK_VOL, 0x1f, 0, speaker_vol_tlv),
|
|
|
|
SOC_SINGLE_TLV("headphone volume", HPOUT_CTRL, HP_VOL, 0x3f, 0, headphone_vol_tlv),
|
|
|
|
};
|
2018-01-23 09:19:00 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
/* PLL divisors */
|
|
|
|
struct pll_div {
|
|
|
|
unsigned int pll_in;
|
|
|
|
unsigned int pll_out;
|
|
|
|
int m;
|
|
|
|
int n_i;
|
|
|
|
int n_f;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct aif1_fs {
|
2018-01-19 12:25:15 +01:00
|
|
|
unsigned samp_rate;
|
|
|
|
int bclk_div;
|
|
|
|
int srbit;
|
|
|
|
#define _SERIES_24_576K 0
|
|
|
|
#define _SERIES_22_579K 1
|
|
|
|
int series;
|
2018-01-12 09:37:28 +01:00
|
|
|
};
|
|
|
|
|
2018-01-22 04:20:17 +01:00
|
|
|
struct kv_map {
|
2018-01-19 12:25:15 +01:00
|
|
|
int val;
|
|
|
|
int bit;
|
2018-01-12 09:37:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2018-01-23 09:19:00 +01:00
|
|
|
* Note : pll code from original tdm/i2s driver.
|
|
|
|
* freq_out = freq_in * N/(m*(2k+1)) , k=1,N=N_i+N_f,N_f=factor*0.2;
|
|
|
|
*/
|
2018-01-12 09:37:28 +01:00
|
|
|
static const struct pll_div codec_pll_div[] = {
|
|
|
|
{128000, 22579200, 1, 529, 1},
|
|
|
|
{192000, 22579200, 1, 352, 4},
|
|
|
|
{256000, 22579200, 1, 264, 3},
|
|
|
|
{384000, 22579200, 1, 176, 2},/*((176+2*0.2)*6000000)/(38*(2*1+1))*/
|
|
|
|
{6000000, 22579200, 38, 429, 0},/*((429+0*0.2)*6000000)/(38*(2*1+1))*/
|
|
|
|
{13000000, 22579200, 19, 99, 0},
|
|
|
|
{19200000, 22579200, 25, 88, 1},
|
2018-01-19 12:25:15 +01:00
|
|
|
{24000000, 22579200, 63, 177, 4},/*((177 + 4 * 0.2) * 24000000) / (63 * (2 * 1 + 1)) */
|
2018-01-12 09:37:28 +01:00
|
|
|
{128000, 24576000, 1, 576, 0},
|
|
|
|
{192000, 24576000, 1, 384, 0},
|
|
|
|
{256000, 24576000, 1, 288, 0},
|
|
|
|
{384000, 24576000, 1, 192, 0},
|
|
|
|
{1411200, 22579200, 1, 48, 0},
|
|
|
|
{2048000, 24576000, 1, 36, 0},
|
|
|
|
{6000000, 24576000, 25, 307, 1},
|
|
|
|
{13000000, 24576000, 42, 238, 1},
|
|
|
|
{19200000, 24576000, 25, 96, 0},
|
2018-01-19 12:25:15 +01:00
|
|
|
{24000000, 24576000, 39, 119, 4},/*((119 + 4 * 0.2) * 24000000) / (39 * (2 * 1 + 1)) */
|
2018-01-12 09:37:28 +01:00
|
|
|
{11289600, 22579200, 1, 6, 0},
|
|
|
|
{12288000, 24576000, 1, 6, 0},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct aif1_fs codec_aif1_fs[] = {
|
2018-01-19 12:25:15 +01:00
|
|
|
{8000, 12, 0},
|
|
|
|
{11025, 8, 1, _SERIES_22_579K},
|
2018-01-12 09:37:28 +01:00
|
|
|
{12000, 8, 2},
|
2018-01-19 12:25:15 +01:00
|
|
|
{16000, 6, 3},
|
|
|
|
{22050, 4, 4, _SERIES_22_579K},
|
|
|
|
{24000, 4, 5},
|
2018-02-05 03:45:55 +01:00
|
|
|
/* {32000, 3, 6}, dividing by 3 is not support */
|
|
|
|
{44100, 2, 7, _SERIES_22_579K},
|
|
|
|
{48000, 2, 8},
|
2018-01-19 12:25:15 +01:00
|
|
|
{96000, 1, 9},
|
2018-01-12 09:37:28 +01:00
|
|
|
};
|
|
|
|
|
2018-01-22 04:20:17 +01:00
|
|
|
static const struct kv_map codec_aif1_lrck[] = {
|
2018-01-12 09:37:28 +01:00
|
|
|
{16, 0},
|
|
|
|
{32, 1},
|
|
|
|
{64, 2},
|
|
|
|
{128, 3},
|
|
|
|
{256, 4},
|
|
|
|
};
|
|
|
|
|
2018-01-22 04:20:17 +01:00
|
|
|
static const struct kv_map codec_aif1_wsize[] = {
|
2018-01-12 09:37:28 +01:00
|
|
|
{8, 0},
|
|
|
|
{16, 1},
|
|
|
|
{20, 2},
|
|
|
|
{24, 3},
|
2018-01-19 12:25:15 +01:00
|
|
|
{32, 3},
|
|
|
|
};
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
static const unsigned ac101_bclkdivs[] = {
|
2018-01-19 12:25:15 +01:00
|
|
|
1, 2, 4, 6,
|
|
|
|
8, 12, 16, 24,
|
|
|
|
32, 48, 64, 96,
|
|
|
|
128, 192, 0, 0,
|
2018-01-12 09:37:28 +01:00
|
|
|
};
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_aif_mute(struct snd_soc_dai *codec_dai, int mute)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
2018-01-26 04:08:09 +01:00
|
|
|
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("%s() L%d mute=%d\n", __func__, __LINE__, mute);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, DAC_VOL_CTRL, mute? 0: 0xA0A0);
|
2018-01-23 09:19:00 +01:00
|
|
|
|
|
|
|
if (!mute) {
|
|
|
|
late_enable_dac(codec, SND_SOC_DAPM_PRE_PMU);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_headphone_event(codec, SND_SOC_DAPM_POST_PMU);
|
2018-01-23 09:19:00 +01:00
|
|
|
if (drc_used) {
|
2018-01-26 04:08:09 +01:00
|
|
|
drc_enable(codec, 1);
|
|
|
|
}
|
2018-02-07 10:35:12 +01:00
|
|
|
if (ac10x->gpiod_spk_amp_gate) {
|
|
|
|
gpiod_set_value(ac10x->gpiod_spk_amp_gate, 1);
|
2018-01-23 09:19:00 +01:00
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
#if _MASTER_MULTI_CODEC != _MASTER_AC101
|
|
|
|
/* enable global clock */
|
|
|
|
ac101_aif1clk(static_ac10x->codec, SND_SOC_DAPM_PRE_PMU);
|
|
|
|
#endif
|
2018-01-23 09:19:00 +01:00
|
|
|
} else {
|
2018-02-07 10:35:12 +01:00
|
|
|
if (ac10x->gpiod_spk_amp_gate) {
|
|
|
|
gpiod_set_value(ac10x->gpiod_spk_amp_gate, 0);
|
2018-01-26 04:08:09 +01:00
|
|
|
}
|
2018-01-23 09:19:00 +01:00
|
|
|
if (drc_used) {
|
2018-01-26 04:08:09 +01:00
|
|
|
drc_enable(codec, 0);
|
2018-01-23 09:19:00 +01:00
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_headphone_event(codec, SND_SOC_DAPM_PRE_PMD);
|
2018-01-23 09:19:00 +01:00
|
|
|
late_enable_dac(codec, SND_SOC_DAPM_POST_PMD);
|
|
|
|
|
|
|
|
ac10x->aif1_clken = 1;
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_aif1clk(codec, SND_SOC_DAPM_POST_PMD);
|
2018-01-23 09:19:00 +01:00
|
|
|
}
|
2018-01-12 09:37:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
void ac101_aif_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *codec_dai)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
|
|
|
int reg_val;
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("%s,line:%d stream = %d, play-active = %d\n", __func__, __LINE__,
|
|
|
|
substream->stream, codec_dai->playback_active);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = (ac101_read(codec, AIF_SR_CTRL) >> 12) & 0xF;
|
2018-01-12 09:37:28 +01:00
|
|
|
if (codec_dai->playback_active && dmic_used && reg_val == 0x4) {
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, AIF_SR_CTRL, (0xf<<AIF1_FS), (0x7<<AIF1_FS));
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
static int ac101_set_pll(struct snd_soc_dai *codec_dai, int pll_id, int source,
|
|
|
|
unsigned int freq_in, unsigned int freq_out)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
int m = 0;
|
|
|
|
int n_i = 0;
|
|
|
|
int n_f = 0;
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("%s, line:%d, pll_id:%d\n", __func__, __LINE__, pll_id);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
if (!freq_out)
|
|
|
|
return 0;
|
|
|
|
if ((freq_in < 128000) || (freq_in > 24576000)) {
|
|
|
|
return -EINVAL;
|
|
|
|
} else if ((freq_in == 24576000) || (freq_in == 22579200)) {
|
|
|
|
if (pll_id == AC101_MCLK1) {
|
|
|
|
/*select aif1 clk source from mclk1*/
|
|
|
|
ac101_update_bits(codec, SYSCLK_CTRL, (0x3<<AIF1CLK_SRC), (0x0<<AIF1CLK_SRC));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pll_id) {
|
|
|
|
case AC101_MCLK1:
|
|
|
|
/*pll source from MCLK1*/
|
|
|
|
ac101_update_bits(codec, SYSCLK_CTRL, (0x3<<PLLCLK_SRC), (0x0<<PLLCLK_SRC));
|
|
|
|
break;
|
|
|
|
case AC101_BCLK1:
|
|
|
|
/*pll source from BCLK1*/
|
|
|
|
ac101_update_bits(codec, SYSCLK_CTRL, (0x3<<PLLCLK_SRC), (0x2<<PLLCLK_SRC));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
/* freq_out = freq_in * n/(m*(2k+1)) , k=1,N=N_i+N_f */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(codec_pll_div); i++) {
|
|
|
|
if ((codec_pll_div[i].pll_in == freq_in) && (codec_pll_div[i].pll_out == freq_out)) {
|
|
|
|
m = codec_pll_div[i].m;
|
|
|
|
n_i = codec_pll_div[i].n_i;
|
|
|
|
n_f = codec_pll_div[i].n_f;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*config pll m*/
|
|
|
|
ac101_update_bits(codec, PLL_CTRL1, (0x3f<<PLL_POSTDIV_M), (m<<PLL_POSTDIV_M));
|
|
|
|
/*config pll n*/
|
|
|
|
ac101_update_bits(codec, PLL_CTRL2, (0x3ff<<PLL_PREDIV_NI), (n_i<<PLL_PREDIV_NI));
|
|
|
|
ac101_update_bits(codec, PLL_CTRL2, (0x7<<PLL_POSTDIV_NF), (n_f<<PLL_POSTDIV_NF));
|
|
|
|
ac101_update_bits(codec, PLL_CTRL2, (0x1<<PLL_EN), (1<<PLL_EN));
|
|
|
|
/*enable pll_enable*/
|
|
|
|
ac101_update_bits(codec, SYSCLK_CTRL, (0x1<<PLLCLK_ENA), (0x1<<PLLCLK_ENA));
|
|
|
|
ac101_update_bits(codec, SYSCLK_CTRL, (0x3<<AIF1CLK_SRC), (0x3<<AIF1CLK_SRC));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ac101_hw_params(struct snd_pcm_substream *substream,
|
2018-01-12 09:37:28 +01:00
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_soc_dai *codec_dai)
|
|
|
|
{
|
|
|
|
int i = 0;
|
2018-01-22 04:20:17 +01:00
|
|
|
int AIF_CLK_CTRL = AIF1_CLK_CTRL;
|
2018-01-26 04:08:09 +01:00
|
|
|
int aif1_word_size = 24;
|
|
|
|
int aif1_slot_size = 32;
|
|
|
|
int aif1_lrck_div;
|
2018-01-12 09:37:28 +01:00
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
2018-01-19 12:25:15 +01:00
|
|
|
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
|
|
|
int reg_val, freq_out;
|
|
|
|
unsigned channels;
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("%s() L%d +++\n", __func__, __LINE__);
|
|
|
|
|
|
|
|
/* Master mode, to clear cpu_dai fifos, disable output bclk & lrck */
|
|
|
|
#if 0
|
|
|
|
ac10x->aif1_clken = 1;
|
|
|
|
ac101_aif1clk(codec, SND_SOC_DAPM_POST_PMD);
|
|
|
|
#endif
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-01-26 04:08:09 +01:00
|
|
|
/* get channels count & slot size */
|
2018-01-19 12:25:15 +01:00
|
|
|
channels = params_channels(params);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
2018-01-26 04:08:09 +01:00
|
|
|
switch (params_format(params)) {
|
|
|
|
case SNDRV_PCM_FORMAT_S24_LE:
|
|
|
|
case SNDRV_PCM_FORMAT_S32_LE:
|
|
|
|
aif1_slot_size = 32;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_S16_LE:
|
|
|
|
default:
|
|
|
|
aif1_slot_size = 16;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set LRCK/BCLK ratio */
|
|
|
|
aif1_lrck_div = aif1_slot_size * channels;
|
2018-01-12 09:37:28 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(codec_aif1_lrck); i++) {
|
2018-01-22 04:20:17 +01:00
|
|
|
if (codec_aif1_lrck[i].val == aif1_lrck_div) {
|
2018-01-12 09:37:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, AIF_CLK_CTRL, (0x7<<AIF1_LRCK_DIV), codec_aif1_lrck[i].bit<<AIF1_LRCK_DIV);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-01-26 04:08:09 +01:00
|
|
|
/* set PLL output freq */
|
2018-01-19 12:25:15 +01:00
|
|
|
freq_out = 24576000;
|
2018-01-12 09:37:28 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(codec_aif1_fs); i++) {
|
2018-02-07 07:02:45 +01:00
|
|
|
if (codec_aif1_fs[i].samp_rate == params_rate(params)) {
|
2018-01-19 12:25:15 +01:00
|
|
|
if (codec_dai->capture_active && dmic_used && codec_aif1_fs[i].samp_rate == 44100) {
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, AIF_SR_CTRL, (0xf<<AIF1_FS), (0x4<<AIF1_FS));
|
2018-01-19 12:25:15 +01:00
|
|
|
} else {
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, AIF_SR_CTRL, (0xf<<AIF1_FS), ((codec_aif1_fs[i].srbit)<<AIF1_FS));
|
2018-01-19 12:25:15 +01:00
|
|
|
}
|
|
|
|
if (codec_aif1_fs[i].series == _SERIES_22_579K)
|
|
|
|
freq_out = 22579200;
|
2018-01-12 09:37:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-01-19 12:25:15 +01:00
|
|
|
|
|
|
|
/* set I2S word size */
|
2018-01-12 09:37:28 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(codec_aif1_wsize); i++) {
|
2018-01-19 12:25:15 +01:00
|
|
|
if (codec_aif1_wsize[i].val == aif1_word_size) {
|
2018-01-12 09:37:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, AIF_CLK_CTRL, (0x3<<AIF1_WORK_SIZ), ((codec_aif1_wsize[i].bit)<<AIF1_WORK_SIZ));
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-01-22 04:20:17 +01:00
|
|
|
/* set TDM slot size */
|
2018-01-26 04:08:09 +01:00
|
|
|
if ((reg_val = codec_aif1_wsize[i].bit) > 2) reg_val = 2;
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, AIF1_ADCDAT_CTRL, 0x3 << AIF1_SLOT_SIZ, reg_val << AIF1_SLOT_SIZ);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
|
|
|
/* setting pll if it's master mode */
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, AIF_CLK_CTRL);
|
2018-01-19 12:25:15 +01:00
|
|
|
if ((reg_val & (0x1 << AIF1_MSTR_MOD)) == 0) {
|
|
|
|
unsigned bclkdiv;
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_set_pll(codec_dai, AC101_MCLK1, 0, ac10x->sysclk, freq_out);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
|
|
|
bclkdiv = freq_out / (aif1_lrck_div * params_rate(params));
|
2018-02-10 08:16:01 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(ac101_bclkdivs) - 1; i++) {
|
|
|
|
if (ac101_bclkdivs[i] >= bclkdiv) {
|
2018-01-19 12:25:15 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, AIF_CLK_CTRL, (0xf<<AIF1_BCLK_DIV), i<<AIF1_BCLK_DIV);
|
2018-01-19 12:25:15 +01:00
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("rate: %d , channels: %d , samp_res: %d",
|
2018-02-07 07:02:45 +01:00
|
|
|
params_rate(params), channels, aif1_slot_size);
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("%s() L%d ---\n", __func__, __LINE__);
|
2018-01-12 09:37:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
|
|
|
int reg_val;
|
2018-01-22 04:20:17 +01:00
|
|
|
int AIF_CLK_CTRL = AIF1_CLK_CTRL;
|
2018-01-12 09:37:28 +01:00
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("%s() L%d\n", __func__, __LINE__);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
/*
|
2018-01-19 12:25:15 +01:00
|
|
|
* master or slave selection
|
|
|
|
* 0 = Master mode
|
|
|
|
* 1 = Slave mode
|
|
|
|
*/
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, AIF_CLK_CTRL);
|
2018-01-19 12:25:15 +01:00
|
|
|
reg_val &= ~(0x1<<AIF1_MSTR_MOD);
|
|
|
|
switch(fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
2018-02-07 10:35:12 +01:00
|
|
|
case SND_SOC_DAIFMT_CBM_CFM: /* codec clk & frm master, ap is slave*/
|
2018-02-10 08:16:01 +01:00
|
|
|
#if _MASTER_MULTI_CODEC == _MASTER_AC101
|
2018-02-07 10:35:12 +01:00
|
|
|
pr_warn("AC101 as Master\n");
|
|
|
|
reg_val |= (0x0<<AIF1_MSTR_MOD);
|
|
|
|
break;
|
2018-02-10 08:16:01 +01:00
|
|
|
#else
|
|
|
|
pr_warn("AC108 as Master\n");
|
|
|
|
#endif
|
2018-02-07 10:35:12 +01:00
|
|
|
case SND_SOC_DAIFMT_CBS_CFS: /* codec clk & frm slave, ap is master*/
|
|
|
|
pr_warn("AC101 as Slave\n");
|
|
|
|
reg_val |= (0x1<<AIF1_MSTR_MOD);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_err("unknwon master/slave format\n");
|
|
|
|
return -EINVAL;
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
2018-01-19 12:25:15 +01:00
|
|
|
|
|
|
|
/*
|
2018-01-30 12:12:47 +01:00
|
|
|
* Enable TDM mode
|
2018-01-19 12:25:15 +01:00
|
|
|
*/
|
2018-01-24 13:18:58 +01:00
|
|
|
reg_val |= (0x1 << AIF1_TDMM_ENA);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, AIF_CLK_CTRL, reg_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
|
|
|
/* i2s mode selection */
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, AIF_CLK_CTRL);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val&=~(3<<AIF1_DATA_FMT);
|
|
|
|
switch(fmt & SND_SOC_DAIFMT_FORMAT_MASK){
|
2018-02-07 10:35:12 +01:00
|
|
|
case SND_SOC_DAIFMT_I2S: /* I2S1 mode */
|
|
|
|
reg_val |= (0x0<<AIF1_DATA_FMT);
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_RIGHT_J: /* Right Justified mode */
|
|
|
|
reg_val |= (0x2<<AIF1_DATA_FMT);
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J: /* Left Justified mode */
|
|
|
|
reg_val |= (0x1<<AIF1_DATA_FMT);
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_DSP_A: /* L reg_val msb after FRM LRC */
|
|
|
|
reg_val |= (0x3<<AIF1_DATA_FMT);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pr_err("%s, line:%d\n", __func__, __LINE__);
|
|
|
|
return -EINVAL;
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, AIF_CLK_CTRL, reg_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
|
|
|
/* DAI signal inversions */
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, AIF_CLK_CTRL);
|
2018-01-12 09:37:28 +01:00
|
|
|
switch(fmt & SND_SOC_DAIFMT_INV_MASK){
|
2018-02-07 10:35:12 +01:00
|
|
|
case SND_SOC_DAIFMT_NB_NF: /* normal bit clock + nor frame */
|
|
|
|
reg_val &= ~(0x1<<AIF1_LRCK_INV);
|
|
|
|
reg_val &= ~(0x1<<AIF1_BCLK_INV);
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_NB_IF: /* normal bclk + inv frm */
|
|
|
|
reg_val |= (0x1<<AIF1_LRCK_INV);
|
|
|
|
reg_val &= ~(0x1<<AIF1_BCLK_INV);
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_NF: /* invert bclk + nor frm */
|
|
|
|
reg_val &= ~(0x1<<AIF1_LRCK_INV);
|
|
|
|
reg_val |= (0x1<<AIF1_BCLK_INV);
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_IF: /* invert bclk + inv frm */
|
|
|
|
reg_val |= (0x1<<AIF1_LRCK_INV);
|
|
|
|
reg_val |= (0x1<<AIF1_BCLK_INV);
|
|
|
|
break;
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, AIF_CLK_CTRL, reg_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_audio_startup(struct snd_pcm_substream *substream,
|
2018-01-12 09:37:28 +01:00
|
|
|
struct snd_soc_dai *codec_dai)
|
|
|
|
{
|
2018-02-07 10:35:12 +01:00
|
|
|
// struct snd_soc_codec *codec = codec_dai->codec;
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("\n\n%s,line:%d\n", __func__, __LINE__);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) {
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
#if _MASTER_MULTI_CODEC == _MASTER_AC101
|
|
|
|
static int ac101_set_clock(int y_start_n_stop) {
|
|
|
|
if (y_start_n_stop) {
|
|
|
|
/* enable global clock */
|
|
|
|
ac101_aif1clk(static_ac10x->codec, SND_SOC_DAPM_PRE_PMU);
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
#endif
|
2018-01-23 09:19:00 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
#if 0
|
2018-02-27 03:58:10 +01:00
|
|
|
static int ac101_set_dai_sysclk(struct snd_soc_dai *codec_dai,
|
|
|
|
int clk_id, unsigned int freq, int dir)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
|
|
|
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
|
|
|
|
|
|
|
AC101_DBG("%s,line:%d, id=%d freq=%d, dir=%d\n", __func__, __LINE__,
|
|
|
|
clk_id, freq, dir);
|
|
|
|
|
|
|
|
ac10x->sysclk = freq;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
static int ac101_trigger(struct snd_pcm_substream *substream, int cmd,
|
2018-01-23 09:19:00 +01:00
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("%s() stream=%d cmd=%d\n",
|
2018-01-23 09:19:00 +01:00
|
|
|
__FUNCTION__, substream->stream, cmd);
|
|
|
|
|
Bugfix: AC101 miss channels order in cpu_dai, channel map IN(0,1,2,3,4,5,6,7)->OUT(2,3,4,5,6,7,0,1)
2018-01-23 09:46:15 +01:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
2018-02-05 03:45:55 +01:00
|
|
|
return ret;
|
2018-01-23 09:19:00 +01:00
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
static const struct snd_soc_dai_ops ac101_aif1_dai_ops = {
|
|
|
|
//.startup = ac101_audio_startup,
|
|
|
|
//.shutdown = ac101_aif_shutdown,
|
|
|
|
//.set_sysclk = ac101_set_dai_sysclk,
|
|
|
|
//.set_pll = ac101_set_pll,
|
|
|
|
//.set_fmt = ac101_set_dai_fmt,
|
|
|
|
//.hw_params = ac101_hw_params,
|
|
|
|
//.trigger = ac101_trigger,
|
|
|
|
//.digital_mute = ac101_aif_mute,
|
2018-01-12 09:37:28 +01:00
|
|
|
};
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
static struct snd_soc_dai_driver ac101_dai[] = {
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
|
|
|
.name = "ac10x-aif1",
|
2018-01-19 12:25:15 +01:00
|
|
|
.id = AIF1_CLK,
|
2018-01-12 09:37:28 +01:00
|
|
|
.playback = {
|
2018-02-07 07:02:45 +01:00
|
|
|
.stream_name = "Playback",
|
2018-01-12 09:37:28 +01:00
|
|
|
.channels_min = 1,
|
2018-01-19 12:25:15 +01:00
|
|
|
.channels_max = 8,
|
2018-02-10 08:16:01 +01:00
|
|
|
.rates = AC101_RATES,
|
|
|
|
.formats = AC101_FORMATS,
|
2018-01-12 09:37:28 +01:00
|
|
|
},
|
2018-01-19 12:25:15 +01:00
|
|
|
#if 0
|
2018-01-12 09:37:28 +01:00
|
|
|
.capture = {
|
2018-02-07 07:02:45 +01:00
|
|
|
.stream_name = "Capture",
|
2018-01-12 09:37:28 +01:00
|
|
|
.channels_min = 1,
|
2018-01-19 12:25:15 +01:00
|
|
|
.channels_max = 8,
|
2018-02-10 08:16:01 +01:00
|
|
|
.rates = AC101_RATES,
|
|
|
|
.formats = AC101_FORMATS,
|
2018-01-19 12:25:15 +01:00
|
|
|
},
|
|
|
|
#endif
|
2018-02-10 08:16:01 +01:00
|
|
|
.ops = &ac101_aif1_dai_ops,
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
};
|
2018-02-10 08:16:01 +01:00
|
|
|
#endif
|
2018-01-12 09:37:28 +01:00
|
|
|
|
|
|
|
static void codec_resume_work(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct ac10x_priv *ac10x = container_of(work, struct ac10x_priv, codec_resume);
|
|
|
|
struct snd_soc_codec *codec = ac10x->codec;
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("%s() L%d +++\n", __func__, __LINE__);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
set_configuration(codec);
|
|
|
|
if (drc_used) {
|
|
|
|
drc_config(codec);
|
|
|
|
}
|
|
|
|
/*enable this bit to prevent leakage from ldoin*/
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, ADDA_TUNE3, (0x1<<OSCEN), (0x1<<OSCEN));
|
|
|
|
|
|
|
|
AC101_DBG("%s() L%d +++\n", __func__, __LINE__);
|
2018-01-19 12:25:15 +01:00
|
|
|
return;
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
2018-02-10 08:16:01 +01:00
|
|
|
switch (level) {
|
|
|
|
case SND_SOC_BIAS_ON:
|
|
|
|
AC101_DBG("%s,line:%d, SND_SOC_BIAS_ON\n", __func__, __LINE__);
|
|
|
|
break;
|
|
|
|
case SND_SOC_BIAS_PREPARE:
|
|
|
|
AC101_DBG("%s,line:%d, SND_SOC_BIAS_PREPARE\n", __func__, __LINE__);
|
|
|
|
break;
|
|
|
|
case SND_SOC_BIAS_STANDBY:
|
|
|
|
AC101_DBG("%s,line:%d, SND_SOC_BIAS_STANDBY\n", __func__, __LINE__);
|
|
|
|
break;
|
|
|
|
case SND_SOC_BIAS_OFF:
|
|
|
|
ac101_update_bits(codec, OMIXER_DACA_CTRL, (0xf<<HPOUTPUTENABLE), (0<<HPOUTPUTENABLE));
|
|
|
|
ac101_update_bits(codec, ADDA_TUNE3, (0x1<<OSCEN), (0<<OSCEN));
|
|
|
|
AC101_DBG("%s,line:%d, SND_SOC_BIAS_OFF\n", __func__, __LINE__);
|
|
|
|
break;
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
snd_soc_codec_get_dapm(codec)->bias_level = level;
|
2018-01-19 12:25:15 +01:00
|
|
|
return 0;
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_codec_probe(struct snd_soc_codec *codec)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct ac10x_priv *ac10x;
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
ac10x = dev_get_drvdata(codec->dev);
|
|
|
|
if (ac10x == NULL) {
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("not set client data %s() L%d\n", __func__, __LINE__);
|
2018-01-12 09:37:28 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
ac10x->codec = codec;
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
INIT_WORK(&ac10x->codec_resume, codec_resume_work);
|
|
|
|
ac10x->dac_enable = 0;
|
|
|
|
ac10x->aif1_clken = 0;
|
|
|
|
ac10x->aif2_clken = 0;
|
|
|
|
mutex_init(&ac10x->dac_mutex);
|
|
|
|
mutex_init(&ac10x->aifclk_mutex);
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
#if _MASTER_MULTI_CODEC == _MASTER_AC101
|
|
|
|
asoc_simple_card_register_set_clock(ac101_set_clock);
|
|
|
|
#endif
|
2018-02-05 03:45:55 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
set_configuration(ac10x->codec);
|
|
|
|
|
|
|
|
/*enable this bit to prevent leakage from ldoin*/
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_update_bits(codec, ADDA_TUNE3, (0x1<<OSCEN), (0x1<<OSCEN));
|
|
|
|
ac101_write(codec, DAC_VOL_CTRL, 0);
|
|
|
|
|
|
|
|
/* customized get/put inteface */
|
|
|
|
for (ret = 0; ret < ARRAY_SIZE(ac101_controls); ret++) {
|
|
|
|
struct snd_kcontrol_new* skn = &ac101_controls[ret];
|
|
|
|
|
|
|
|
skn->get = snd_ac101_get_volsw;
|
|
|
|
skn->put = snd_ac101_put_volsw;
|
|
|
|
}
|
|
|
|
ret = snd_soc_add_codec_controls(codec, ac101_controls, ARRAY_SIZE(ac101_controls));
|
2018-01-12 09:37:28 +01:00
|
|
|
if (ret) {
|
|
|
|
pr_err("[ac10x] Failed to register audio mode control, "
|
|
|
|
"will continue without it.\n");
|
|
|
|
}
|
2018-01-22 04:20:17 +01:00
|
|
|
return 0;
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* power down chip */
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_codec_remove(struct snd_soc_codec *codec)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
2018-02-07 10:35:12 +01:00
|
|
|
// struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
2018-01-12 09:37:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_codec_suspend(struct snd_soc_codec *codec)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
|
|
|
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("[codec]:suspend\n");
|
|
|
|
regcache_cache_only(ac10x->regmap101, true);
|
2018-01-12 09:37:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_codec_resume(struct snd_soc_codec *codec)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
|
|
|
struct ac10x_priv *ac10x = snd_soc_codec_get_drvdata(codec);
|
2018-01-19 12:25:15 +01:00
|
|
|
int ret;
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
AC101_DBG("[codec]:resume");
|
2018-01-19 12:25:15 +01:00
|
|
|
|
|
|
|
/* Sync reg_cache with the hardware */
|
2018-02-10 08:16:01 +01:00
|
|
|
regcache_cache_only(ac10x->regmap101, false);
|
|
|
|
ret = regcache_sync(ac10x->regmap101);
|
2018-01-19 12:25:15 +01:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(codec->dev, "Failed to sync register cache: %d\n", ret);
|
2018-02-10 08:16:01 +01:00
|
|
|
regcache_cache_only(ac10x->regmap101, true);
|
2018-01-19 12:25:15 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
|
2018-01-12 09:37:28 +01:00
|
|
|
schedule_work(&ac10x->codec_resume);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-02-10 08:16:01 +01:00
|
|
|
|
|
|
|
/***************************************************************************/
|
|
|
|
static ssize_t ac101_debug_store(struct device *dev,
|
|
|
|
struct device_attribute *attr, const char *buf, size_t count)
|
|
|
|
{
|
|
|
|
static int val = 0, flag = 0;
|
|
|
|
u8 reg,num,i=0;
|
|
|
|
u16 value_w,value_r[128];
|
|
|
|
struct ac10x_priv *ac10x = dev_get_drvdata(dev);
|
|
|
|
val = simple_strtol(buf, NULL, 16);
|
|
|
|
flag = (val >> 24) & 0xF;
|
|
|
|
if(flag) {
|
|
|
|
reg = (val >> 16) & 0xFF;
|
|
|
|
value_w = val & 0xFFFF;
|
|
|
|
ac101_write(ac10x->codec, reg, value_w);
|
|
|
|
printk("write 0x%x to reg:0x%x\n",value_w,reg);
|
|
|
|
} else {
|
|
|
|
reg =(val>>8)& 0xFF;
|
|
|
|
num=val&0xff;
|
|
|
|
printk("\n");
|
|
|
|
printk("read:start add:0x%x,count:0x%x\n",reg,num);
|
|
|
|
do {
|
|
|
|
value_r[i] = ac101_read(ac10x->codec, reg);
|
|
|
|
printk("0x%x: 0x%04x ",reg,value_r[i]);
|
|
|
|
reg+=1;
|
|
|
|
i++;
|
|
|
|
if(i == num)
|
|
|
|
printk("\n");
|
|
|
|
if(i%4==0)
|
|
|
|
printk("\n");
|
|
|
|
} while(i<num);
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
static ssize_t ac101_debug_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
printk("echo flag|reg|val > ac10x\n");
|
|
|
|
printk("eg read star addres=0x06,count 0x10:echo 0610 >ac10x\n");
|
|
|
|
printk("eg write value:0x13fe to address:0x06 :echo 10613fe > ac10x\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR(ac10x, 0644, ac101_debug_show, ac101_debug_store);
|
|
|
|
|
|
|
|
static struct attribute *audio_debug_attrs[] = {
|
|
|
|
&dev_attr_ac10x.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group audio_debug_attr_group = {
|
|
|
|
.name = "ac101_debug",
|
|
|
|
.attrs = audio_debug_attrs,
|
|
|
|
};
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
/************************************************************/
|
|
|
|
static const struct regmap_config ac101_regmap = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 16,
|
|
|
|
.reg_stride = 1,
|
|
|
|
.max_register = 0xB5,
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
2018-01-12 09:37:28 +01:00
|
|
|
};
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
2018-02-10 08:16:01 +01:00
|
|
|
struct ac10x_priv *ac10x = i2c_get_clientdata(i2c);
|
2018-01-12 09:37:28 +01:00
|
|
|
int ret = 0;
|
2018-02-10 08:16:01 +01:00
|
|
|
unsigned v = 0;
|
|
|
|
|
|
|
|
AC101_DBG("%s,line:%d\n", __func__, __LINE__);
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-01-30 12:12:47 +01:00
|
|
|
static_ac10x = ac10x;
|
2018-01-19 12:25:15 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
ac10x->regmap101 = devm_regmap_init_i2c(i2c, &ac101_regmap);
|
|
|
|
if (IS_ERR(ac10x->regmap101)) {
|
|
|
|
ret = PTR_ERR(ac10x->regmap101);
|
2018-01-19 12:25:15 +01:00
|
|
|
dev_err(&i2c->dev, "Fail to initialize I/O: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
ret = regmap_read(ac10x->regmap101, CHIP_AUDIO_RST, &v);
|
2018-01-19 12:25:15 +01:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&i2c->dev, "failed to read vendor ID: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (v != AC101_CHIP_ID) {
|
|
|
|
dev_err(&i2c->dev, "chip is not AC101\n");
|
|
|
|
dev_err(&i2c->dev, "Expected %X\n", AC101_CHIP_ID);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
ret = sysfs_create_group(&i2c->dev.kobj, &audio_debug_attr_group);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("failed to create attr group\n");
|
|
|
|
}
|
2018-01-26 04:08:09 +01:00
|
|
|
|
2018-02-07 10:35:12 +01:00
|
|
|
ac10x->gpiod_spk_amp_gate = devm_gpiod_get_optional(&i2c->dev, "spk-amp-switch", GPIOD_OUT_LOW);
|
|
|
|
if (IS_ERR(ac10x->gpiod_spk_amp_gate)) {
|
|
|
|
ac10x->gpiod_spk_amp_gate = NULL;
|
2018-01-26 04:08:09 +01:00
|
|
|
dev_err(&i2c->dev, "failed get spk-amp-switch in device tree\n");
|
|
|
|
}
|
2018-01-12 09:37:28 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2018-01-22 04:20:17 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
void ac101_shutdown(struct i2c_client *i2c)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
|
|
|
struct ac10x_priv *ac10x = i2c_get_clientdata(i2c);
|
2018-02-10 08:16:01 +01:00
|
|
|
struct snd_soc_codec *codec = ac10x->codec;
|
|
|
|
int reg_val;
|
2018-01-22 04:20:17 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
if (codec == NULL) {
|
2018-02-07 10:35:12 +01:00
|
|
|
pr_err("%s() L%d: no sound card.\n", __func__, __LINE__);
|
2018-01-22 04:20:17 +01:00
|
|
|
return;
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
2018-01-22 04:20:17 +01:00
|
|
|
|
2018-01-12 09:37:28 +01:00
|
|
|
/*set headphone volume to 0*/
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, HPOUT_CTRL);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x3f<<HP_VOL);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, HPOUT_CTRL, reg_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
|
|
|
/*disable pa*/
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, HPOUT_CTRL);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0x1<<HPPA_EN);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, HPOUT_CTRL, reg_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
|
|
|
/*hardware xzh support*/
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, OMIXER_DACA_CTRL);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~(0xf<<HPOUTPUTENABLE);
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, OMIXER_DACA_CTRL, reg_val);
|
2018-01-12 09:37:28 +01:00
|
|
|
|
|
|
|
/*unmute l/r headphone pa*/
|
2018-02-10 08:16:01 +01:00
|
|
|
reg_val = ac101_read(codec, HPOUT_CTRL);
|
2018-01-12 09:37:28 +01:00
|
|
|
reg_val &= ~((0x1<<RHPPA_MUTE)|(0x1<<LHPPA_MUTE));
|
2018-02-10 08:16:01 +01:00
|
|
|
ac101_write(codec, HPOUT_CTRL, reg_val);
|
2018-01-22 04:20:17 +01:00
|
|
|
return;
|
2018-01-12 09:37:28 +01:00
|
|
|
}
|
2018-01-22 04:20:17 +01:00
|
|
|
|
2018-02-10 08:16:01 +01:00
|
|
|
int ac101_remove(struct i2c_client *i2c)
|
2018-01-12 09:37:28 +01:00
|
|
|
{
|
|
|
|
sysfs_remove_group(&i2c->dev.kobj, &audio_debug_attr_group);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("ASoC ac10x driver");
|
|
|
|
MODULE_AUTHOR("huangxin,liushaohua");
|
2018-01-22 04:20:17 +01:00
|
|
|
MODULE_AUTHOR("PeterYang<linsheng.yang@seeed.cc>");
|