ASoC: codec: Update codec driver to component driver

Some alsa API are removed in kernel-4.19 which would cause
codec driver compile failure. Update codec driver to fix it.

Change-Id: Ie358ec1863082166958059c179300b453d2a03ad
Signed-off-by: Meng Wang <mengw@codeaurora.org>
This commit is contained in:
Meng Wang
2018-09-06 10:49:18 +08:00
committed by Gerrit - the friendly Code Review server
parent ee084a068e
commit 15c825d077
59 changed files with 8532 additions and 6916 deletions

View File

@@ -157,19 +157,19 @@ struct wcd937x_mbhc_zdet_param {
u16 btn7;
};
static int wcd937x_mbhc_request_irq(struct snd_soc_codec *codec,
static int wcd937x_mbhc_request_irq(struct snd_soc_component *component,
int irq, irq_handler_t handler,
const char *name, void *data)
{
struct wcd937x_priv *wcd937x = dev_get_drvdata(codec->dev);
struct wcd937x_priv *wcd937x = dev_get_drvdata(component->dev);
return wcd_request_irq(&wcd937x->irq_info, irq, name, handler, data);
}
static void wcd937x_mbhc_irq_control(struct snd_soc_codec *codec,
static void wcd937x_mbhc_irq_control(struct snd_soc_component *component,
int irq, bool enable)
{
struct wcd937x_priv *wcd937x = dev_get_drvdata(codec->dev);
struct wcd937x_priv *wcd937x = dev_get_drvdata(component->dev);
if (enable)
wcd_enable_irq(&wcd937x->irq_info, irq);
@@ -177,44 +177,45 @@ static void wcd937x_mbhc_irq_control(struct snd_soc_codec *codec,
wcd_disable_irq(&wcd937x->irq_info, irq);
}
static int wcd937x_mbhc_free_irq(struct snd_soc_codec *codec,
static int wcd937x_mbhc_free_irq(struct snd_soc_component *component,
int irq, void *data)
{
struct wcd937x_priv *wcd937x = dev_get_drvdata(codec->dev);
struct wcd937x_priv *wcd937x = dev_get_drvdata(component->dev);
wcd_free_irq(&wcd937x->irq_info, irq, data);
return 0;
}
static void wcd937x_mbhc_clk_setup(struct snd_soc_codec *codec,
static void wcd937x_mbhc_clk_setup(struct snd_soc_component *component,
bool enable)
{
if (enable)
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_1,
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_CTL_1,
0x80, 0x80);
else
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_1,
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_CTL_1,
0x80, 0x00);
}
static int wcd937x_mbhc_btn_to_num(struct snd_soc_codec *codec)
static int wcd937x_mbhc_btn_to_num(struct snd_soc_component *component)
{
return snd_soc_read(codec, WCD937X_ANA_MBHC_RESULT_3) & 0x7;
return snd_soc_component_read32(component, WCD937X_ANA_MBHC_RESULT_3) &
0x7;
}
static void wcd937x_mbhc_mbhc_bias_control(struct snd_soc_codec *codec,
static void wcd937x_mbhc_mbhc_bias_control(struct snd_soc_component *component,
bool enable)
{
if (enable)
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_ELECT,
snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_ELECT,
0x01, 0x01);
else
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_ELECT,
snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_ELECT,
0x01, 0x00);
}
static void wcd937x_mbhc_program_btn_thr(struct snd_soc_codec *codec,
static void wcd937x_mbhc_program_btn_thr(struct snd_soc_component *component,
s16 *btn_low, s16 *btn_high,
int num_btn, bool is_micbias)
{
@@ -222,16 +223,17 @@ static void wcd937x_mbhc_program_btn_thr(struct snd_soc_codec *codec,
int vth;
if (num_btn > WCD_MBHC_DEF_BUTTONS) {
dev_err(codec->dev, "%s: invalid number of buttons: %d\n",
dev_err(component->dev, "%s: invalid number of buttons: %d\n",
__func__, num_btn);
return;
}
for (i = 0; i < num_btn; i++) {
vth = ((btn_high[i] * 2) / 25) & 0x3F;
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_BTN0 + i,
0xFC, vth << 2);
dev_dbg(codec->dev, "%s: btn_high[%d]: %d, vth: %d\n",
snd_soc_component_update_bits(component,
WCD937X_ANA_MBHC_BTN0 + i,
0xFC, vth << 2);
dev_dbg(component->dev, "%s: btn_high[%d]: %d, vth: %d\n",
__func__, i, btn_high[i], vth);
}
}
@@ -262,7 +264,8 @@ static bool wcd937x_mbhc_micb_en_status(struct wcd_mbhc *mbhc, int micb_num)
u8 val = 0;
if (micb_num == MIC_BIAS_2) {
val = ((snd_soc_read(mbhc->codec, WCD937X_ANA_MICB2) & 0xC0)
val = ((snd_soc_component_read32(mbhc->component,
WCD937X_ANA_MICB2) & 0xC0)
>> 6);
if (val == 0x01)
return true;
@@ -270,48 +273,51 @@ static bool wcd937x_mbhc_micb_en_status(struct wcd_mbhc *mbhc, int micb_num)
return false;
}
static bool wcd937x_mbhc_hph_pa_on_status(struct snd_soc_codec *codec)
static bool wcd937x_mbhc_hph_pa_on_status(struct snd_soc_component *component)
{
return (snd_soc_read(codec, WCD937X_ANA_HPH) & 0xC0) ? true : false;
return (snd_soc_component_read32(component, WCD937X_ANA_HPH) & 0xC0) ?
true : false;
}
static void wcd937x_mbhc_hph_l_pull_up_control(struct snd_soc_codec *codec,
int pull_up_cur)
static void wcd937x_mbhc_hph_l_pull_up_control(
struct snd_soc_component *component,
int pull_up_cur)
{
/* Default pull up current to 2uA */
if (pull_up_cur > HS_PULLUP_I_OFF || pull_up_cur < HS_PULLUP_I_3P0_UA ||
pull_up_cur == HS_PULLUP_I_DEFAULT)
pull_up_cur = HS_PULLUP_I_2P0_UA;
dev_dbg(codec->dev, "%s: HS pull up current:%d\n",
dev_dbg(component->dev, "%s: HS pull up current:%d\n",
__func__, pull_up_cur);
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_INT_MECH_DET_CURRENT,
0x1F, pull_up_cur);
snd_soc_component_update_bits(component,
WCD937X_MBHC_NEW_INT_MECH_DET_CURRENT,
0x1F, pull_up_cur);
}
static int wcd937x_mbhc_request_micbias(struct snd_soc_codec *codec,
static int wcd937x_mbhc_request_micbias(struct snd_soc_component *component,
int micb_num, int req)
{
int ret = 0;
ret = wcd937x_micbias_control(codec, micb_num, req, false);
ret = wcd937x_micbias_control(component, micb_num, req, false);
return ret;
}
static void wcd937x_mbhc_micb_ramp_control(struct snd_soc_codec *codec,
static void wcd937x_mbhc_micb_ramp_control(struct snd_soc_component *component,
bool enable)
{
if (enable) {
snd_soc_update_bits(codec, WCD937X_ANA_MICB2_RAMP,
snd_soc_component_update_bits(component, WCD937X_ANA_MICB2_RAMP,
0x1C, 0x0C);
snd_soc_update_bits(codec, WCD937X_ANA_MICB2_RAMP,
snd_soc_component_update_bits(component, WCD937X_ANA_MICB2_RAMP,
0x80, 0x80);
} else {
snd_soc_update_bits(codec, WCD937X_ANA_MICB2_RAMP,
snd_soc_component_update_bits(component, WCD937X_ANA_MICB2_RAMP,
0x80, 0x00);
snd_soc_update_bits(codec, WCD937X_ANA_MICB2_RAMP,
snd_soc_component_update_bits(component, WCD937X_ANA_MICB2_RAMP,
0x1C, 0x00);
}
}
@@ -321,26 +327,27 @@ static struct firmware_cal *wcd937x_get_hwdep_fw_cal(struct wcd_mbhc *mbhc,
{
struct wcd937x_mbhc *wcd937x_mbhc;
struct firmware_cal *hwdep_cal;
struct snd_soc_codec *codec = mbhc->codec;
struct snd_soc_component *component = mbhc->component;
wcd937x_mbhc = container_of(mbhc, struct wcd937x_mbhc, wcd_mbhc);
if (!codec) {
pr_err("%s: NULL codec pointer\n", __func__);
if (!component) {
pr_err("%s: NULL component pointer\n", __func__);
return NULL;
}
hwdep_cal = wcdcal_get_fw_cal(wcd937x_mbhc->fw_data, type);
if (!hwdep_cal)
dev_err(codec->dev, "%s: cal not sent by %d\n",
dev_err(component->dev, "%s: cal not sent by %d\n",
__func__, type);
return hwdep_cal;
}
static int wcd937x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_codec *codec,
int micb_num, bool req_en)
static int wcd937x_mbhc_micb_ctrl_threshold_mic(
struct snd_soc_component *component,
int micb_num, bool req_en)
{
struct wcd937x_pdata *pdata = dev_get_platdata(codec->dev);
struct wcd937x_pdata *pdata = dev_get_platdata(component->dev);
int rc, micb_mv;
if (micb_num != MIC_BIAS_2)
@@ -355,7 +362,7 @@ static int wcd937x_mbhc_micb_ctrl_threshold_mic(struct snd_soc_codec *codec,
micb_mv = req_en ? WCD_MBHC_THR_HS_MICB_MV : pdata->micbias.micb2_mv;
rc = wcd937x_mbhc_micb_adjust_voltage(codec, micb_mv, MIC_BIAS_2);
rc = wcd937x_mbhc_micb_adjust_voltage(component, micb_mv, MIC_BIAS_2);
return rc;
}
@@ -418,25 +425,25 @@ ramp_down:
}
}
static void wcd937x_mbhc_zdet_ramp(struct snd_soc_codec *codec,
static void wcd937x_mbhc_zdet_ramp(struct snd_soc_component *component,
struct wcd937x_mbhc_zdet_param *zdet_param,
int32_t *zl, int32_t *zr, s16 *d1_a)
{
struct wcd937x_priv *wcd937x = dev_get_drvdata(codec->dev);
struct wcd937x_priv *wcd937x = dev_get_drvdata(component->dev);
int32_t zdet = 0;
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_ZDET_ANA_CTL, 0x70,
zdet_param->ldo_ctl << 4);
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_BTN5, 0xFC,
zdet_param->btn5);
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_BTN6, 0xFC,
zdet_param->btn6);
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_BTN7, 0xFC,
zdet_param->btn7);
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_ZDET_ANA_CTL, 0x0F,
zdet_param->noff);
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_ZDET_RAMP_CTL, 0x0F,
zdet_param->nshift);
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_ZDET_ANA_CTL,
0x70, zdet_param->ldo_ctl << 4);
snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_BTN5, 0xFC,
zdet_param->btn5);
snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_BTN6, 0xFC,
zdet_param->btn6);
snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_BTN7, 0xFC,
zdet_param->btn7);
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_ZDET_ANA_CTL,
0x0F, zdet_param->noff);
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_ZDET_RAMP_CTL,
0x0F, zdet_param->nshift);
if (!zl)
goto z_right;
@@ -466,17 +473,18 @@ z_right:
*zr = zdet;
}
static inline void wcd937x_wcd_mbhc_qfuse_cal(struct snd_soc_codec *codec,
int32_t *z_val, int flag_l_r)
static inline void wcd937x_wcd_mbhc_qfuse_cal(
struct snd_soc_component *component,
int32_t *z_val, int flag_l_r)
{
s16 q1;
int q1_cal;
if (*z_val < (WCD937X_ZDET_VAL_400/1000))
q1 = snd_soc_read(codec,
q1 = snd_soc_component_read32(component,
WCD937X_DIGITAL_EFUSE_REG_23 + (2 * flag_l_r));
else
q1 = snd_soc_read(codec,
q1 = snd_soc_component_read32(component,
WCD937X_DIGITAL_EFUSE_REG_24 + (2 * flag_l_r));
if (q1 & 0x80)
q1_cal = (10000 - ((q1 & 0x7F) * 25));
@@ -489,8 +497,8 @@ static inline void wcd937x_wcd_mbhc_qfuse_cal(struct snd_soc_codec *codec,
static void wcd937x_wcd_mbhc_calc_impedance(struct wcd_mbhc *mbhc, uint32_t *zl,
uint32_t *zr)
{
struct snd_soc_codec *codec = mbhc->codec;
struct wcd937x_priv *wcd937x = dev_get_drvdata(codec->dev);
struct snd_soc_component *component = mbhc->component;
struct wcd937x_priv *wcd937x = dev_get_drvdata(component->dev);
s16 reg0, reg1, reg2, reg3, reg4;
int32_t z1L, z1R, z1Ls;
int zMono, z_diff1, z_diff2;
@@ -512,13 +520,15 @@ static void wcd937x_wcd_mbhc_calc_impedance(struct wcd_mbhc *mbhc, uint32_t *zl,
WCD_MBHC_RSC_ASSERT_LOCKED(mbhc);
reg0 = snd_soc_read(codec, WCD937X_ANA_MBHC_BTN5);
reg1 = snd_soc_read(codec, WCD937X_ANA_MBHC_BTN6);
reg2 = snd_soc_read(codec, WCD937X_ANA_MBHC_BTN7);
reg3 = snd_soc_read(codec, WCD937X_MBHC_CTL_CLK);
reg4 = snd_soc_read(codec, WCD937X_MBHC_NEW_ZDET_ANA_CTL);
reg0 = snd_soc_component_read32(component, WCD937X_ANA_MBHC_BTN5);
reg1 = snd_soc_component_read32(component, WCD937X_ANA_MBHC_BTN6);
reg2 = snd_soc_component_read32(component, WCD937X_ANA_MBHC_BTN7);
reg3 = snd_soc_component_read32(component, WCD937X_MBHC_CTL_CLK);
reg4 = snd_soc_component_read32(component,
WCD937X_MBHC_NEW_ZDET_ANA_CTL);
if (snd_soc_read(codec, WCD937X_ANA_MBHC_ELECT) & 0x80) {
if (snd_soc_component_read32(component, WCD937X_ANA_MBHC_ELECT) &
0x80) {
is_fsm_disable = true;
regmap_update_bits(wcd937x->regmap,
WCD937X_ANA_MBHC_ELECT, 0x80, 0x00);
@@ -536,7 +546,7 @@ static void wcd937x_wcd_mbhc_calc_impedance(struct wcd_mbhc *mbhc, uint32_t *zl,
/* First get impedance on Left */
d1 = d1_a[1];
zdet_param_ptr = &zdet_param[1];
wcd937x_mbhc_zdet_ramp(codec, zdet_param_ptr, &z1L, NULL, d1);
wcd937x_mbhc_zdet_ramp(component, zdet_param_ptr, &z1L, NULL, d1);
if (!WCD937X_MBHC_IS_SECOND_RAMP_REQUIRED(z1L))
goto left_ch_impedance;
@@ -553,7 +563,7 @@ static void wcd937x_wcd_mbhc_calc_impedance(struct wcd_mbhc *mbhc, uint32_t *zl,
zdet_param_ptr = &zdet_param[3];
d1 = d1_a[3];
}
wcd937x_mbhc_zdet_ramp(codec, zdet_param_ptr, &z1L, NULL, d1);
wcd937x_mbhc_zdet_ramp(component, zdet_param_ptr, &z1L, NULL, d1);
left_ch_impedance:
if ((z1L == WCD937X_ZDET_FLOATING_IMPEDANCE) ||
@@ -563,13 +573,13 @@ left_ch_impedance:
d1 = d1_a[1];
} else {
*zl = z1L/1000;
wcd937x_wcd_mbhc_qfuse_cal(codec, zl, 0);
wcd937x_wcd_mbhc_qfuse_cal(component, zl, 0);
}
dev_dbg(codec->dev, "%s: impedance on HPH_L = %d(ohms)\n",
dev_dbg(component->dev, "%s: impedance on HPH_L = %d(ohms)\n",
__func__, *zl);
/* Start of right impedance ramp and calculation */
wcd937x_mbhc_zdet_ramp(codec, zdet_param_ptr, NULL, &z1R, d1);
wcd937x_mbhc_zdet_ramp(component, zdet_param_ptr, NULL, &z1R, d1);
if (WCD937X_MBHC_IS_SECOND_RAMP_REQUIRED(z1R)) {
if (((z1R > WCD937X_ZDET_VAL_1200) &&
(zdet_param_ptr->noff == 0x6)) ||
@@ -587,7 +597,8 @@ left_ch_impedance:
zdet_param_ptr = &zdet_param[3];
d1 = d1_a[3];
}
wcd937x_mbhc_zdet_ramp(codec, zdet_param_ptr, NULL, &z1R, d1);
wcd937x_mbhc_zdet_ramp(component, zdet_param_ptr, NULL,
&z1R, d1);
}
right_ch_impedance:
if ((z1R == WCD937X_ZDET_FLOATING_IMPEDANCE) ||
@@ -595,15 +606,15 @@ right_ch_impedance:
*zr = WCD937X_ZDET_FLOATING_IMPEDANCE;
} else {
*zr = z1R/1000;
wcd937x_wcd_mbhc_qfuse_cal(codec, zr, 1);
wcd937x_wcd_mbhc_qfuse_cal(component, zr, 1);
}
dev_dbg(codec->dev, "%s: impedance on HPH_R = %d(ohms)\n",
dev_dbg(component->dev, "%s: impedance on HPH_R = %d(ohms)\n",
__func__, *zr);
/* Mono/stereo detection */
if ((*zl == WCD937X_ZDET_FLOATING_IMPEDANCE) &&
(*zr == WCD937X_ZDET_FLOATING_IMPEDANCE)) {
dev_dbg(codec->dev,
dev_dbg(component->dev,
"%s: plug type is invalid or extension cable\n",
__func__);
goto zdet_complete;
@@ -612,40 +623,46 @@ right_ch_impedance:
(*zr == WCD937X_ZDET_FLOATING_IMPEDANCE) ||
((*zl < WCD_MONO_HS_MIN_THR) && (*zr > WCD_MONO_HS_MIN_THR)) ||
((*zl > WCD_MONO_HS_MIN_THR) && (*zr < WCD_MONO_HS_MIN_THR))) {
dev_dbg(codec->dev,
dev_dbg(component->dev,
"%s: Mono plug type with one ch floating or shorted to GND\n",
__func__);
mbhc->hph_type = WCD_MBHC_HPH_MONO;
goto zdet_complete;
}
snd_soc_update_bits(codec, WCD937X_HPH_R_ATEST, 0x02, 0x02);
snd_soc_update_bits(codec, WCD937X_HPH_PA_CTL2, 0x40, 0x01);
snd_soc_component_update_bits(component, WCD937X_HPH_R_ATEST,
0x02, 0x02);
snd_soc_component_update_bits(component, WCD937X_HPH_PA_CTL2,
0x40, 0x01);
if (*zl < (WCD937X_ZDET_VAL_32/1000))
wcd937x_mbhc_zdet_ramp(codec, &zdet_param[0], &z1Ls, NULL, d1);
wcd937x_mbhc_zdet_ramp(component, &zdet_param[0], &z1Ls,
NULL, d1);
else
wcd937x_mbhc_zdet_ramp(codec, &zdet_param[1], &z1Ls, NULL, d1);
snd_soc_update_bits(codec, WCD937X_HPH_PA_CTL2, 0x40, 0x00);
snd_soc_update_bits(codec, WCD937X_HPH_R_ATEST, 0x02, 0x00);
wcd937x_mbhc_zdet_ramp(component, &zdet_param[1], &z1Ls,
NULL, d1);
snd_soc_component_update_bits(component, WCD937X_HPH_PA_CTL2,
0x40, 0x00);
snd_soc_component_update_bits(component, WCD937X_HPH_R_ATEST,
0x02, 0x00);
z1Ls /= 1000;
wcd937x_wcd_mbhc_qfuse_cal(codec, &z1Ls, 0);
wcd937x_wcd_mbhc_qfuse_cal(component, &z1Ls, 0);
/* Parallel of left Z and 9 ohm pull down resistor */
zMono = ((*zl) * 9) / ((*zl) + 9);
z_diff1 = (z1Ls > zMono) ? (z1Ls - zMono) : (zMono - z1Ls);
z_diff2 = ((*zl) > z1Ls) ? ((*zl) - z1Ls) : (z1Ls - (*zl));
if ((z_diff1 * (*zl + z1Ls)) > (z_diff2 * (z1Ls + zMono))) {
dev_dbg(codec->dev, "%s: stereo plug type detected\n",
dev_dbg(component->dev, "%s: stereo plug type detected\n",
__func__);
mbhc->hph_type = WCD_MBHC_HPH_STEREO;
} else {
dev_dbg(codec->dev, "%s: MONO plug type detected\n",
dev_dbg(component->dev, "%s: MONO plug type detected\n",
__func__);
mbhc->hph_type = WCD_MBHC_HPH_MONO;
}
zdet_complete:
snd_soc_write(codec, WCD937X_ANA_MBHC_BTN5, reg0);
snd_soc_write(codec, WCD937X_ANA_MBHC_BTN6, reg1);
snd_soc_write(codec, WCD937X_ANA_MBHC_BTN7, reg2);
snd_soc_component_write(component, WCD937X_ANA_MBHC_BTN5, reg0);
snd_soc_component_write(component, WCD937X_ANA_MBHC_BTN6, reg1);
snd_soc_component_write(component, WCD937X_ANA_MBHC_BTN7, reg2);
/* Turn on 100k pull down on HPHL */
regmap_update_bits(wcd937x->regmap,
WCD937X_ANA_MBHC_MECH, 0x01, 0x01);
@@ -655,97 +672,98 @@ zdet_complete:
regmap_update_bits(wcd937x->regmap,
WCD937X_ANA_MBHC_MECH, 0x80, 0x80);
snd_soc_write(codec, WCD937X_MBHC_NEW_ZDET_ANA_CTL, reg4);
snd_soc_write(codec, WCD937X_MBHC_CTL_CLK, reg3);
snd_soc_component_write(component, WCD937X_MBHC_NEW_ZDET_ANA_CTL, reg4);
snd_soc_component_write(component, WCD937X_MBHC_CTL_CLK, reg3);
if (is_fsm_disable)
regmap_update_bits(wcd937x->regmap,
WCD937X_ANA_MBHC_ELECT, 0x80, 0x80);
}
static void wcd937x_mbhc_gnd_det_ctrl(struct snd_soc_codec *codec, bool enable)
static void wcd937x_mbhc_gnd_det_ctrl(struct snd_soc_component *component,
bool enable)
{
if (enable) {
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_MECH,
snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_MECH,
0x02, 0x02);
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_MECH,
snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_MECH,
0x40, 0x40);
} else {
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_MECH,
snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_MECH,
0x40, 0x00);
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_MECH,
snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_MECH,
0x02, 0x00);
}
}
static void wcd937x_mbhc_hph_pull_down_ctrl(struct snd_soc_codec *codec,
static void wcd937x_mbhc_hph_pull_down_ctrl(struct snd_soc_component *component,
bool enable)
{
if (enable) {
snd_soc_update_bits(codec, WCD937X_HPH_PA_CTL2,
snd_soc_component_update_bits(component, WCD937X_HPH_PA_CTL2,
0x40, 0x40);
snd_soc_update_bits(codec, WCD937X_HPH_PA_CTL2,
snd_soc_component_update_bits(component, WCD937X_HPH_PA_CTL2,
0x10, 0x10);
} else {
snd_soc_update_bits(codec, WCD937X_HPH_PA_CTL2,
snd_soc_component_update_bits(component, WCD937X_HPH_PA_CTL2,
0x40, 0x00);
snd_soc_update_bits(codec, WCD937X_HPH_PA_CTL2,
snd_soc_component_update_bits(component, WCD937X_HPH_PA_CTL2,
0x10, 0x00);
}
}
static void wcd937x_mbhc_moisture_config(struct wcd_mbhc *mbhc)
{
struct snd_soc_codec *codec = mbhc->codec;
struct snd_soc_component *component = mbhc->component;
if ((mbhc->moist_rref == R_OFF) ||
(mbhc->mbhc_cfg->enable_usbc_analog)) {
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2,
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_CTL_2,
0x0C, R_OFF << 2);
return;
}
/* Do not enable moisture detection if jack type is NC */
if (!mbhc->hphl_swh) {
dev_dbg(codec->dev, "%s: disable moisture detection for NC\n",
dev_dbg(component->dev, "%s: disable moisture detection for NC\n",
__func__);
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2,
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_CTL_2,
0x0C, R_OFF << 2);
return;
}
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2,
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_CTL_2,
0x0C, mbhc->moist_rref << 2);
}
static void wcd937x_mbhc_moisture_detect_en(struct wcd_mbhc *mbhc, bool enable)
{
struct snd_soc_codec *codec = mbhc->codec;
struct snd_soc_component *component = mbhc->component;
if (enable)
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2,
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_CTL_2,
0x0C, mbhc->moist_rref << 2);
else
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2,
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_CTL_2,
0x0C, R_OFF << 2);
}
static bool wcd937x_mbhc_get_moisture_status(struct wcd_mbhc *mbhc)
{
struct snd_soc_codec *codec = mbhc->codec;
struct snd_soc_component *component = mbhc->component;
bool ret = false;
if ((mbhc->moist_rref == R_OFF) ||
(mbhc->mbhc_cfg->enable_usbc_analog)) {
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2,
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_CTL_2,
0x0C, R_OFF << 2);
goto done;
}
/* Do not enable moisture detection if jack type is NC */
if (!mbhc->hphl_swh) {
dev_dbg(codec->dev, "%s: disable moisture detection for NC\n",
dev_dbg(component->dev, "%s: disable moisture detection for NC\n",
__func__);
snd_soc_update_bits(codec, WCD937X_MBHC_NEW_CTL_2,
snd_soc_component_update_bits(component, WCD937X_MBHC_NEW_CTL_2,
0x0C, R_OFF << 2);
goto done;
}
@@ -753,12 +771,13 @@ static bool wcd937x_mbhc_get_moisture_status(struct wcd_mbhc *mbhc)
/* If moisture_en is already enabled, then skip to plug type
* detection.
*/
if ((snd_soc_read(codec, WCD937X_MBHC_NEW_CTL_2) & 0x0C))
if ((snd_soc_component_read32(component, WCD937X_MBHC_NEW_CTL_2) &
0x0C))
goto done;
wcd937x_mbhc_moisture_detect_en(mbhc, true);
/* Read moisture comparator status */
ret = ((snd_soc_read(codec, WCD937X_MBHC_NEW_FSM_STATUS)
ret = ((snd_soc_component_read32(component, WCD937X_MBHC_NEW_FSM_STATUS)
& 0x20) ? 0 : 1);
done:
@@ -769,9 +788,9 @@ done:
static void wcd937x_mbhc_moisture_polling_ctrl(struct wcd_mbhc *mbhc,
bool enable)
{
struct snd_soc_codec *codec = mbhc->codec;
struct snd_soc_component *component = mbhc->component;
snd_soc_update_bits(codec,
snd_soc_component_update_bits(component,
WCD937X_MBHC_NEW_INT_MOISTURE_DET_POLLING_CTRL,
0x04, (enable << 2));
}
@@ -805,19 +824,22 @@ static const struct wcd_mbhc_cb mbhc_cb = {
static int wcd937x_get_hph_type(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
struct wcd937x_mbhc *wcd937x_mbhc = wcd937x_soc_get_mbhc(codec);
struct snd_soc_component *component =
snd_soc_kcontrol_component(kcontrol);
struct wcd937x_mbhc *wcd937x_mbhc = wcd937x_soc_get_mbhc(component);
struct wcd_mbhc *mbhc;
if (!wcd937x_mbhc) {
dev_err(codec->dev, "%s: mbhc not initialized!\n", __func__);
dev_err(component->dev, "%s: mbhc not initialized!\n",
__func__);
return -EINVAL;
}
mbhc = &wcd937x_mbhc->wcd_mbhc;
ucontrol->value.integer.value[0] = (u32) mbhc->hph_type;
dev_dbg(codec->dev, "%s: hph_type = %u\n", __func__, mbhc->hph_type);
dev_dbg(component->dev, "%s: hph_type = %u\n", __func__,
mbhc->hph_type);
return 0;
}
@@ -828,18 +850,21 @@ static int wcd937x_hph_impedance_get(struct snd_kcontrol *kcontrol,
uint32_t zl, zr;
bool hphr;
struct soc_multi_mixer_control *mc;
struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
struct wcd937x_mbhc *wcd937x_mbhc = wcd937x_soc_get_mbhc(codec);
struct snd_soc_component *component =
snd_soc_kcontrol_component(kcontrol);
struct wcd937x_mbhc *wcd937x_mbhc = wcd937x_soc_get_mbhc(component);
if (!wcd937x_mbhc) {
dev_err(codec->dev, "%s: mbhc not initialized!\n", __func__);
dev_err(component->dev, "%s: mbhc not initialized!\n",
__func__);
return -EINVAL;
}
mc = (struct soc_multi_mixer_control *)(kcontrol->private_value);
hphr = mc->shift;
wcd_mbhc_get_impedance(&wcd937x_mbhc->wcd_mbhc, &zl, &zr);
dev_dbg(codec->dev, "%s: zl=%u(ohms), zr=%u(ohms)\n", __func__, zl, zr);
dev_dbg(component->dev, "%s: zl=%u(ohms), zr=%u(ohms)\n", __func__,
zl, zr);
ucontrol->value.integer.value[0] = hphr ? zr : zl;
return 0;
@@ -883,22 +908,22 @@ EXPORT_SYMBOL(wcd937x_mbhc_get_impedance);
/*
* wcd937x_mbhc_hs_detect: starts mbhc insertion/removal functionality
* @codec: handle to snd_soc_codec *
* @component: handle to snd_soc_component *
* @mbhc_cfg: handle to mbhc configuration structure
* return 0 if mbhc_start is success or error code in case of failure
*/
int wcd937x_mbhc_hs_detect(struct snd_soc_codec *codec,
int wcd937x_mbhc_hs_detect(struct snd_soc_component *component,
struct wcd_mbhc_config *mbhc_cfg)
{
struct wcd937x_priv *wcd937x = NULL;
struct wcd937x_mbhc *wcd937x_mbhc = NULL;
if (!codec) {
pr_err("%s: codec is NULL\n", __func__);
if (!component) {
pr_err("%s: component is NULL\n", __func__);
return -EINVAL;
}
wcd937x = snd_soc_codec_get_drvdata(codec);
wcd937x = snd_soc_component_get_drvdata(component);
if (!wcd937x) {
pr_err("%s: wcd937x is NULL\n", __func__);
return -EINVAL;
@@ -906,7 +931,8 @@ int wcd937x_mbhc_hs_detect(struct snd_soc_codec *codec,
wcd937x_mbhc = wcd937x->mbhc;
if (!wcd937x_mbhc) {
dev_err(codec->dev, "%s: mbhc not initialized!\n", __func__);
dev_err(component->dev, "%s: mbhc not initialized!\n",
__func__);
return -EINVAL;
}
@@ -916,19 +942,19 @@ EXPORT_SYMBOL(wcd937x_mbhc_hs_detect);
/*
* wcd937x_mbhc_hs_detect_exit: stop mbhc insertion/removal functionality
* @codec: handle to snd_soc_codec *
* @component: handle to snd_soc_component *
*/
void wcd937x_mbhc_hs_detect_exit(struct snd_soc_codec *codec)
void wcd937x_mbhc_hs_detect_exit(struct snd_soc_component *component)
{
struct wcd937x_priv *wcd937x = NULL;
struct wcd937x_mbhc *wcd937x_mbhc = NULL;
if (!codec) {
pr_err("%s: codec is NULL\n", __func__);
if (!component) {
pr_err("%s: component is NULL\n", __func__);
return;
}
wcd937x = snd_soc_codec_get_drvdata(codec);
wcd937x = snd_soc_component_get_drvdata(component);
if (!wcd937x) {
pr_err("%s: wcd937x is NULL\n", __func__);
return;
@@ -936,7 +962,8 @@ void wcd937x_mbhc_hs_detect_exit(struct snd_soc_codec *codec)
wcd937x_mbhc = wcd937x->mbhc;
if (!wcd937x_mbhc) {
dev_err(codec->dev, "%s: mbhc not initialized!\n", __func__);
dev_err(component->dev, "%s: mbhc not initialized!\n",
__func__);
return;
}
wcd_mbhc_stop(&wcd937x_mbhc->wcd_mbhc);
@@ -947,17 +974,17 @@ EXPORT_SYMBOL(wcd937x_mbhc_hs_detect_exit);
* wcd937x_mbhc_post_ssr_init: initialize mbhc for
* wcd937x post subsystem restart
* @mbhc: poniter to wcd937x_mbhc structure
* @codec: handle to snd_soc_codec *
* @component: handle to snd_soc_component *
*
* return 0 if mbhc_init is success or error code in case of failure
*/
int wcd937x_mbhc_post_ssr_init(struct wcd937x_mbhc *mbhc,
struct snd_soc_codec *codec)
struct snd_soc_component *component)
{
int ret = 0;
struct wcd_mbhc *wcd_mbhc = NULL;
if (!mbhc || !codec)
if (!mbhc || !component)
return -EINVAL;
wcd_mbhc = &mbhc->wcd_mbhc;
@@ -966,14 +993,14 @@ int wcd937x_mbhc_post_ssr_init(struct wcd937x_mbhc *mbhc,
return -EINVAL;
}
wcd937x_mbhc_hs_detect_exit(codec);
wcd937x_mbhc_hs_detect_exit(component);
wcd_mbhc_deinit(wcd_mbhc);
snd_soc_update_bits(codec, WCD937X_ANA_MBHC_MECH,
snd_soc_component_update_bits(component, WCD937X_ANA_MBHC_MECH,
0x20, 0x20);
ret = wcd_mbhc_init(wcd_mbhc, codec, &mbhc_cb, &intr_ids,
ret = wcd_mbhc_init(wcd_mbhc, component, &mbhc_cb, &intr_ids,
wcd_mbhc_registers, WCD937X_ZDET_SUPPORTED);
if (ret) {
dev_err(codec->dev, "%s: mbhc initialization failed\n",
dev_err(component->dev, "%s: mbhc initialization failed\n",
__func__);
goto done;
}
@@ -986,24 +1013,25 @@ EXPORT_SYMBOL(wcd937x_mbhc_post_ssr_init);
/*
* wcd937x_mbhc_init: initialize mbhc for wcd937x
* @mbhc: poniter to wcd937x_mbhc struct pointer to store the configs
* @codec: handle to snd_soc_codec *
* @component: handle to snd_soc_component *
* @fw_data: handle to firmware data
*
* return 0 if mbhc_init is success or error code in case of failure
*/
int wcd937x_mbhc_init(struct wcd937x_mbhc **mbhc, struct snd_soc_codec *codec,
struct fw_info *fw_data)
int wcd937x_mbhc_init(struct wcd937x_mbhc **mbhc,
struct snd_soc_component *component,
struct fw_info *fw_data)
{
struct wcd937x_mbhc *wcd937x_mbhc = NULL;
struct wcd_mbhc *wcd_mbhc = NULL;
int ret = 0;
if (!codec) {
pr_err("%s: codec is NULL\n", __func__);
if (!component) {
pr_err("%s: component is NULL\n", __func__);
return -EINVAL;
}
wcd937x_mbhc = devm_kzalloc(codec->dev, sizeof(struct wcd937x_mbhc),
wcd937x_mbhc = devm_kzalloc(component->dev, sizeof(struct wcd937x_mbhc),
GFP_KERNEL);
if (!wcd937x_mbhc)
return -ENOMEM;
@@ -1021,43 +1049,43 @@ int wcd937x_mbhc_init(struct wcd937x_mbhc **mbhc, struct snd_soc_codec *codec,
/* Setting default mbhc detection logic to ADC */
wcd_mbhc->mbhc_detection_logic = WCD_DETECTION_ADC;
ret = wcd_mbhc_init(wcd_mbhc, codec, &mbhc_cb,
ret = wcd_mbhc_init(wcd_mbhc, component, &mbhc_cb,
&intr_ids, wcd_mbhc_registers,
WCD937X_ZDET_SUPPORTED);
if (ret) {
dev_err(codec->dev, "%s: mbhc initialization failed\n",
dev_err(component->dev, "%s: mbhc initialization failed\n",
__func__);
goto err;
}
(*mbhc) = wcd937x_mbhc;
snd_soc_add_codec_controls(codec, impedance_detect_controls,
snd_soc_add_component_controls(component, impedance_detect_controls,
ARRAY_SIZE(impedance_detect_controls));
snd_soc_add_codec_controls(codec, hph_type_detect_controls,
snd_soc_add_component_controls(component, hph_type_detect_controls,
ARRAY_SIZE(hph_type_detect_controls));
return 0;
err:
devm_kfree(codec->dev, wcd937x_mbhc);
devm_kfree(component->dev, wcd937x_mbhc);
return ret;
}
EXPORT_SYMBOL(wcd937x_mbhc_init);
/*
* wcd937x_mbhc_deinit: deinitialize mbhc for wcd937x
* @codec: handle to snd_soc_codec *
* @component: handle to snd_soc_component *
*/
void wcd937x_mbhc_deinit(struct snd_soc_codec *codec)
void wcd937x_mbhc_deinit(struct snd_soc_component *component)
{
struct wcd937x_priv *wcd937x;
struct wcd937x_mbhc *wcd937x_mbhc;
if (!codec) {
pr_err("%s: codec is NULL\n", __func__);
if (!component) {
pr_err("%s: component is NULL\n", __func__);
return;
}
wcd937x = snd_soc_codec_get_drvdata(codec);
wcd937x = snd_soc_component_get_drvdata(component);
if (!wcd937x) {
pr_err("%s: wcd937x is NULL\n", __func__);
return;
@@ -1066,7 +1094,7 @@ void wcd937x_mbhc_deinit(struct snd_soc_codec *codec)
wcd937x_mbhc = wcd937x->mbhc;
if (wcd937x_mbhc) {
wcd_mbhc_deinit(&wcd937x_mbhc->wcd_mbhc);
devm_kfree(codec->dev, wcd937x_mbhc);
devm_kfree(component->dev, wcd937x_mbhc);
}
}
EXPORT_SYMBOL(wcd937x_mbhc_deinit);