|
|
@ -48,86 +48,6 @@ |
|
|
|
|
|
|
|
#define TWL4030_CACHEREGNUM (TWL4030_REG_MISC_SET_2 + 1) |
|
|
|
|
|
|
|
/* |
|
|
|
* twl4030 register cache & default register settings |
|
|
|
*/ |
|
|
|
static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = { |
|
|
|
0x00, /* this register not used */ |
|
|
|
0x00, /* REG_CODEC_MODE (0x1) */ |
|
|
|
0x00, /* REG_OPTION (0x2) */ |
|
|
|
0x00, /* REG_UNKNOWN (0x3) */ |
|
|
|
0x00, /* REG_MICBIAS_CTL (0x4) */ |
|
|
|
0x00, /* REG_ANAMICL (0x5) */ |
|
|
|
0x00, /* REG_ANAMICR (0x6) */ |
|
|
|
0x00, /* REG_AVADC_CTL (0x7) */ |
|
|
|
0x00, /* REG_ADCMICSEL (0x8) */ |
|
|
|
0x00, /* REG_DIGMIXING (0x9) */ |
|
|
|
0x0f, /* REG_ATXL1PGA (0xA) */ |
|
|
|
0x0f, /* REG_ATXR1PGA (0xB) */ |
|
|
|
0x0f, /* REG_AVTXL2PGA (0xC) */ |
|
|
|
0x0f, /* REG_AVTXR2PGA (0xD) */ |
|
|
|
0x00, /* REG_AUDIO_IF (0xE) */ |
|
|
|
0x00, /* REG_VOICE_IF (0xF) */ |
|
|
|
0x3f, /* REG_ARXR1PGA (0x10) */ |
|
|
|
0x3f, /* REG_ARXL1PGA (0x11) */ |
|
|
|
0x3f, /* REG_ARXR2PGA (0x12) */ |
|
|
|
0x3f, /* REG_ARXL2PGA (0x13) */ |
|
|
|
0x25, /* REG_VRXPGA (0x14) */ |
|
|
|
0x00, /* REG_VSTPGA (0x15) */ |
|
|
|
0x00, /* REG_VRX2ARXPGA (0x16) */ |
|
|
|
0x00, /* REG_AVDAC_CTL (0x17) */ |
|
|
|
0x00, /* REG_ARX2VTXPGA (0x18) */ |
|
|
|
0x32, /* REG_ARXL1_APGA_CTL (0x19) */ |
|
|
|
0x32, /* REG_ARXR1_APGA_CTL (0x1A) */ |
|
|
|
0x32, /* REG_ARXL2_APGA_CTL (0x1B) */ |
|
|
|
0x32, /* REG_ARXR2_APGA_CTL (0x1C) */ |
|
|
|
0x00, /* REG_ATX2ARXPGA (0x1D) */ |
|
|
|
0x00, /* REG_BT_IF (0x1E) */ |
|
|
|
0x55, /* REG_BTPGA (0x1F) */ |
|
|
|
0x00, /* REG_BTSTPGA (0x20) */ |
|
|
|
0x00, /* REG_EAR_CTL (0x21) */ |
|
|
|
0x00, /* REG_HS_SEL (0x22) */ |
|
|
|
0x00, /* REG_HS_GAIN_SET (0x23) */ |
|
|
|
0x00, /* REG_HS_POPN_SET (0x24) */ |
|
|
|
0x00, /* REG_PREDL_CTL (0x25) */ |
|
|
|
0x00, /* REG_PREDR_CTL (0x26) */ |
|
|
|
0x00, /* REG_PRECKL_CTL (0x27) */ |
|
|
|
0x00, /* REG_PRECKR_CTL (0x28) */ |
|
|
|
0x00, /* REG_HFL_CTL (0x29) */ |
|
|
|
0x00, /* REG_HFR_CTL (0x2A) */ |
|
|
|
0x05, /* REG_ALC_CTL (0x2B) */ |
|
|
|
0x00, /* REG_ALC_SET1 (0x2C) */ |
|
|
|
0x00, /* REG_ALC_SET2 (0x2D) */ |
|
|
|
0x00, /* REG_BOOST_CTL (0x2E) */ |
|
|
|
0x00, /* REG_SOFTVOL_CTL (0x2F) */ |
|
|
|
0x13, /* REG_DTMF_FREQSEL (0x30) */ |
|
|
|
0x00, /* REG_DTMF_TONEXT1H (0x31) */ |
|
|
|
0x00, /* REG_DTMF_TONEXT1L (0x32) */ |
|
|
|
0x00, /* REG_DTMF_TONEXT2H (0x33) */ |
|
|
|
0x00, /* REG_DTMF_TONEXT2L (0x34) */ |
|
|
|
0x79, /* REG_DTMF_TONOFF (0x35) */ |
|
|
|
0x11, /* REG_DTMF_WANONOFF (0x36) */ |
|
|
|
0x00, /* REG_I2S_RX_SCRAMBLE_H (0x37) */ |
|
|
|
0x00, /* REG_I2S_RX_SCRAMBLE_M (0x38) */ |
|
|
|
0x00, /* REG_I2S_RX_SCRAMBLE_L (0x39) */ |
|
|
|
0x06, /* REG_APLL_CTL (0x3A) */ |
|
|
|
0x00, /* REG_DTMF_CTL (0x3B) */ |
|
|
|
0x44, /* REG_DTMF_PGA_CTL2 (0x3C) */ |
|
|
|
0x69, /* REG_DTMF_PGA_CTL1 (0x3D) */ |
|
|
|
0x00, /* REG_MISC_SET_1 (0x3E) */ |
|
|
|
0x00, /* REG_PCMBTMUX (0x3F) */ |
|
|
|
0x00, /* not used (0x40) */ |
|
|
|
0x00, /* not used (0x41) */ |
|
|
|
0x00, /* not used (0x42) */ |
|
|
|
0x00, /* REG_RX_PATH_SEL (0x43) */ |
|
|
|
0x32, /* REG_VDL_APGA_CTL (0x44) */ |
|
|
|
0x00, /* REG_VIBRA_CTL (0x45) */ |
|
|
|
0x00, /* REG_VIBRA_SET (0x46) */ |
|
|
|
0x00, /* REG_VIBRA_PWM_SET (0x47) */ |
|
|
|
0x00, /* REG_ANAMIC_GAIN (0x48) */ |
|
|
|
0x00, /* REG_MISC_SET_2 (0x49) */ |
|
|
|
}; |
|
|
|
|
|
|
|
/* codec private data */ |
|
|
|
struct twl4030_priv { |
|
|
|
unsigned int codec_powered; |
|
|
@ -150,81 +70,108 @@ struct twl4030_priv { |
|
|
|
u8 earpiece_enabled; |
|
|
|
u8 predrivel_enabled, predriver_enabled; |
|
|
|
u8 carkitl_enabled, carkitr_enabled; |
|
|
|
u8 ctl_cache[TWL4030_REG_PRECKR_CTL - TWL4030_REG_EAR_CTL + 1]; |
|
|
|
|
|
|
|
struct twl4030_codec_data *pdata; |
|
|
|
}; |
|
|
|
|
|
|
|
/* |
|
|
|
* read twl4030 register cache |
|
|
|
*/ |
|
|
|
static inline unsigned int twl4030_read_reg_cache(struct snd_soc_codec *codec, |
|
|
|
unsigned int reg) |
|
|
|
static void tw4030_init_ctl_cache(struct twl4030_priv *twl4030) |
|
|
|
{ |
|
|
|
u8 *cache = codec->reg_cache; |
|
|
|
|
|
|
|
if (reg >= TWL4030_CACHEREGNUM) |
|
|
|
return -EIO; |
|
|
|
int i; |
|
|
|
u8 byte; |
|
|
|
|
|
|
|
return cache[reg]; |
|
|
|
for (i = TWL4030_REG_EAR_CTL; i <= TWL4030_REG_PRECKR_CTL; i++) { |
|
|
|
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte, i); |
|
|
|
twl4030->ctl_cache[i - TWL4030_REG_EAR_CTL] = byte; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* write twl4030 register cache |
|
|
|
*/ |
|
|
|
static inline void twl4030_write_reg_cache(struct snd_soc_codec *codec, |
|
|
|
u8 reg, u8 value) |
|
|
|
static unsigned int twl4030_read(struct snd_soc_codec *codec, unsigned int reg) |
|
|
|
{ |
|
|
|
u8 *cache = codec->reg_cache; |
|
|
|
struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); |
|
|
|
u8 value = 0; |
|
|
|
|
|
|
|
if (reg >= TWL4030_CACHEREGNUM) |
|
|
|
return; |
|
|
|
cache[reg] = value; |
|
|
|
return -EIO; |
|
|
|
|
|
|
|
switch (reg) { |
|
|
|
case TWL4030_REG_EAR_CTL: |
|
|
|
case TWL4030_REG_PREDL_CTL: |
|
|
|
case TWL4030_REG_PREDR_CTL: |
|
|
|
case TWL4030_REG_PRECKL_CTL: |
|
|
|
case TWL4030_REG_PRECKR_CTL: |
|
|
|
case TWL4030_REG_HS_GAIN_SET: |
|
|
|
value = twl4030->ctl_cache[reg - TWL4030_REG_EAR_CTL]; |
|
|
|
break; |
|
|
|
default: |
|
|
|
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &value, reg); |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
return value; |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* write to the twl4030 register space |
|
|
|
*/ |
|
|
|
static int twl4030_write(struct snd_soc_codec *codec, |
|
|
|
unsigned int reg, unsigned int value) |
|
|
|
static bool twl4030_can_write_to_chip(struct twl4030_priv *twl4030, |
|
|
|
unsigned int reg) |
|
|
|
{ |
|
|
|
struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); |
|
|
|
int write_to_reg = 0; |
|
|
|
bool write_to_reg = false; |
|
|
|
|
|
|
|
twl4030_write_reg_cache(codec, reg, value); |
|
|
|
/* Decide if the given register can be written */ |
|
|
|
switch (reg) { |
|
|
|
case TWL4030_REG_EAR_CTL: |
|
|
|
if (twl4030->earpiece_enabled) |
|
|
|
write_to_reg = 1; |
|
|
|
write_to_reg = true; |
|
|
|
break; |
|
|
|
case TWL4030_REG_PREDL_CTL: |
|
|
|
if (twl4030->predrivel_enabled) |
|
|
|
write_to_reg = 1; |
|
|
|
write_to_reg = true; |
|
|
|
break; |
|
|
|
case TWL4030_REG_PREDR_CTL: |
|
|
|
if (twl4030->predriver_enabled) |
|
|
|
write_to_reg = 1; |
|
|
|
write_to_reg = true; |
|
|
|
break; |
|
|
|
case TWL4030_REG_PRECKL_CTL: |
|
|
|
if (twl4030->carkitl_enabled) |
|
|
|
write_to_reg = 1; |
|
|
|
write_to_reg = true; |
|
|
|
break; |
|
|
|
case TWL4030_REG_PRECKR_CTL: |
|
|
|
if (twl4030->carkitr_enabled) |
|
|
|
write_to_reg = 1; |
|
|
|
write_to_reg = true; |
|
|
|
break; |
|
|
|
case TWL4030_REG_HS_GAIN_SET: |
|
|
|
if (twl4030->hsl_enabled || twl4030->hsr_enabled) |
|
|
|
write_to_reg = 1; |
|
|
|
write_to_reg = true; |
|
|
|
break; |
|
|
|
default: |
|
|
|
/* All other register can be written */ |
|
|
|
write_to_reg = 1; |
|
|
|
write_to_reg = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
return write_to_reg; |
|
|
|
} |
|
|
|
|
|
|
|
static int twl4030_write(struct snd_soc_codec *codec, unsigned int reg, |
|
|
|
unsigned int value) |
|
|
|
{ |
|
|
|
struct twl4030_priv *twl4030 = snd_soc_codec_get_drvdata(codec); |
|
|
|
|
|
|
|
/* Update the ctl cache */ |
|
|
|
switch (reg) { |
|
|
|
case TWL4030_REG_EAR_CTL: |
|
|
|
case TWL4030_REG_PREDL_CTL: |
|
|
|
case TWL4030_REG_PREDR_CTL: |
|
|
|
case TWL4030_REG_PRECKL_CTL: |
|
|
|
case TWL4030_REG_PRECKR_CTL: |
|
|
|
case TWL4030_REG_HS_GAIN_SET: |
|
|
|
twl4030->ctl_cache[reg - TWL4030_REG_EAR_CTL] = value; |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
if (write_to_reg) |
|
|
|
return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, |
|
|
|
value, reg); |
|
|
|
|
|
|
|
if (twl4030_can_write_to_chip(twl4030, reg)) |
|
|
|
return twl_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
@ -252,46 +199,14 @@ static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable) |
|
|
|
else |
|
|
|
mode = twl4030_audio_disable_resource(TWL4030_AUDIO_RES_POWER); |
|
|
|
|
|
|
|
if (mode >= 0) { |
|
|
|
twl4030_write_reg_cache(codec, TWL4030_REG_CODEC_MODE, mode); |
|
|
|
if (mode >= 0) |
|
|
|
twl4030->codec_powered = enable; |
|
|
|
} |
|
|
|
|
|
|
|
/* REVISIT: this delay is present in TI sample drivers */ |
|
|
|
/* but there seems to be no TRM requirement for it */ |
|
|
|
udelay(10); |
|
|
|
} |
|
|
|
|
|
|
|
static inline void twl4030_check_defaults(struct snd_soc_codec *codec) |
|
|
|
{ |
|
|
|
int i, difference = 0; |
|
|
|
u8 val; |
|
|
|
|
|
|
|
dev_dbg(codec->dev, "Checking TWL audio default configuration\n"); |
|
|
|
for (i = 1; i <= TWL4030_REG_MISC_SET_2; i++) { |
|
|
|
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &val, i); |
|
|
|
if (val != twl4030_reg[i]) { |
|
|
|
difference++; |
|
|
|
dev_dbg(codec->dev, |
|
|
|
"Reg 0x%02x: chip: 0x%02x driver: 0x%02x\n", |
|
|
|
i, val, twl4030_reg[i]); |
|
|
|
} |
|
|
|
} |
|
|
|
dev_dbg(codec->dev, "Found %d non-matching registers. %s\n", |
|
|
|
difference, difference ? "Not OK" : "OK"); |
|
|
|
} |
|
|
|
|
|
|
|
static inline void twl4030_reset_registers(struct snd_soc_codec *codec) |
|
|
|
{ |
|
|
|
int i; |
|
|
|
|
|
|
|
/* set all audio section registers to reasonable defaults */ |
|
|
|
for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++) |
|
|
|
if (i != TWL4030_REG_APLL_CTL) |
|
|
|
twl4030_write(codec, i, twl4030_reg[i]); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
static void twl4030_setup_pdata_of(struct twl4030_codec_data *pdata, |
|
|
|
struct device_node *node) |
|
|
|
{ |
|
|
@ -372,27 +287,17 @@ static void twl4030_init_chip(struct snd_soc_codec *codec) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* Check defaults, if instructed before anything else */ |
|
|
|
if (pdata && pdata->check_defaults) |
|
|
|
twl4030_check_defaults(codec); |
|
|
|
|
|
|
|
/* Reset registers, if no setup data or if instructed to do so */ |
|
|
|
if (!pdata || (pdata && pdata->reset_registers)) |
|
|
|
twl4030_reset_registers(codec); |
|
|
|
|
|
|
|
/* Refresh APLL_CTL register from HW */ |
|
|
|
twl_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte, |
|
|
|
TWL4030_REG_APLL_CTL); |
|
|
|
twl4030_write_reg_cache(codec, TWL4030_REG_APLL_CTL, byte); |
|
|
|
/* Initialize the local ctl register cache */ |
|
|
|
tw4030_init_ctl_cache(twl4030); |
|
|
|
|
|
|
|
/* anti-pop when changing analog gain */ |
|
|
|
reg = twl4030_read_reg_cache(codec, TWL4030_REG_MISC_SET_1); |
|
|
|
reg = twl4030_read(codec, TWL4030_REG_MISC_SET_1); |
|
|
|
twl4030_write(codec, TWL4030_REG_MISC_SET_1, |
|
|
|
reg | TWL4030_SMOOTH_ANAVOL_EN); |
|
|
|
reg | TWL4030_SMOOTH_ANAVOL_EN); |
|
|
|
|
|
|
|
twl4030_write(codec, TWL4030_REG_OPTION, |
|
|
|
TWL4030_ATXL1_EN | TWL4030_ATXR1_EN | |
|
|
|
TWL4030_ARXL2_EN | TWL4030_ARXR2_EN); |
|
|
|
TWL4030_ATXL1_EN | TWL4030_ATXR1_EN | |
|
|
|
TWL4030_ARXL2_EN | TWL4030_ARXR2_EN); |
|
|
|
|
|
|
|
/* REG_ARXR2_APGA_CTL reset according to the TRM: 0dB, DA_EN */ |
|
|
|
twl4030_write(codec, TWL4030_REG_ARXR2_APGA_CTL, 0x32); |
|
|
@ -403,19 +308,19 @@ static void twl4030_init_chip(struct snd_soc_codec *codec) |
|
|
|
|
|
|
|
twl4030->pdata = pdata; |
|
|
|
|
|
|
|
reg = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET); |
|
|
|
reg = twl4030_read(codec, TWL4030_REG_HS_POPN_SET); |
|
|
|
reg &= ~TWL4030_RAMP_DELAY; |
|
|
|
reg |= (pdata->ramp_delay_value << 2); |
|
|
|
twl4030_write_reg_cache(codec, TWL4030_REG_HS_POPN_SET, reg); |
|
|
|
twl4030_write(codec, TWL4030_REG_HS_POPN_SET, reg); |
|
|