mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
To: Srinivasa Rao Mandadapu <srivasam@codeaurora.org>,
	agross@kernel.org, bjorn.andersson@linaro.org,
	lgirdwood@gmail.com, broonie@kernel.org, robh+dt@kernel.org,
	plai@codeaurora.org, bgoswami@codeaurora.org, perex@perex.cz,
	tiwai@suse.com, rohitkr@codeaurora.org,
	linux-arm-msm@vger.kernel.org, alsa-devel@alsa-project.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	swboyd@chromium.org, judyhsiao@chromium.org
Cc: Venkata Prasad Potturu <potturu@codeaurora.org>
Subject: Re: [PATCH] ASoC: codecs: MBHC: Add support for special headset
Date: Wed, 10 Nov 2021 10:12:30 +0000	[thread overview]
Message-ID: <8422a82f-5aa7-2458-8080-87f330fa63ea@linaro.org> (raw)
In-Reply-To: <1635938324-17763-1-git-send-email-srivasam@codeaurora.org>

Thanks for adding this support.

few minor nits,

On 03/11/2021 11:18, Srinivasa Rao Mandadapu wrote:
> Update MBHC driver to support special headset such as apple
> and huwawei headsets.
> 
> Signed-off-by: Srinivasa Rao Mandadapu <srivasam@codeaurora.org>
> Co-developed-by: Venkata Prasad Potturu <potturu@codeaurora.org>
> Signed-off-by: Venkata Prasad Potturu <potturu@codeaurora.org>
> ---
>   sound/soc/codecs/wcd-mbhc-v2.c | 78 +++++++++++++++++++++++++++++++++++++++---
>   1 file changed, 74 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/soc/codecs/wcd-mbhc-v2.c b/sound/soc/codecs/wcd-mbhc-v2.c
> index 405128c..3b4cd39 100644
> --- a/sound/soc/codecs/wcd-mbhc-v2.c
> +++ b/sound/soc/codecs/wcd-mbhc-v2.c
> @@ -1022,6 +1022,57 @@ static int wcd_mbhc_get_plug_from_adc(struct wcd_mbhc *mbhc, int adc_result)
>   	return plug_type;
>   }
>   
> +static int wcd_mbhc_get_spl_hs_thres(struct wcd_mbhc *mbhc)
> +{
> +	int hs_threshold, micbias_mv;
> +
> +	micbias_mv = wcd_mbhc_get_micbias(mbhc);
> +	if (mbhc->cfg->hs_thr && mbhc->cfg->micb_mv != WCD_MBHC_ADC_MICBIAS_MV) {
> +		if (mbhc->cfg->micb_mv == micbias_mv)
> +			hs_threshold = mbhc->cfg->hs_thr;
> +		else
> +			hs_threshold = (mbhc->cfg->hs_thr * micbias_mv) /
> +								mbhc->cfg->micb_mv;

You should consider using 100 chars per line, so that reading is much easy.

> +	} else {
> +		hs_threshold = ((WCD_MBHC_ADC_HS_THRESHOLD_MV * micbias_mv) /
> +							WCD_MBHC_ADC_MICBIAS_MV);
> +	}
> +	return hs_threshold;
> +}
> +
> +static bool wcd_mbhc_check_for_spl_headset(struct wcd_mbhc *mbhc)
> +{
> +	bool is_spl_hs = false;
> +	int output_mv, hs_threshold, hph_threshold;
> +
> +	if (!mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic)
> +		return false;
> +
> +	/* Bump up MIC_BIAS2 to 2.7V */
> +	mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(mbhc->component, MIC_BIAS_2, true);
> +	usleep_range(10000, 10100);
> +
> +	output_mv = wcd_measure_adc_once(mbhc, MUX_CTL_IN2P);
> +	hs_threshold = wcd_mbhc_get_spl_hs_thres(mbhc);
> +	hph_threshold = wcd_mbhc_adc_get_hph_thres(mbhc);
> +
> +	if (output_mv > hs_threshold || output_mv < hph_threshold) {
> +		if (mbhc->force_linein == true)
> +			is_spl_hs = false;
> +	} else {
> +		is_spl_hs = true;
> +	}
> +
> +	/* Back MIC_BIAS2 to 1.8v if the type is not special headset */
> +	if (!is_spl_hs) {
> +		mbhc->mbhc_cb->mbhc_micb_ctrl_thr_mic(mbhc->component, MIC_BIAS_2, false);
> +		/* Add 10ms delay for micbias to settle */
> +		usleep_range(10000, 10100);
> +	}
> +
> +	return is_spl_hs;
> +}
> +
>   static void wcd_correct_swch_plug(struct work_struct *work)
>   {
>   	struct wcd_mbhc *mbhc;
> @@ -1029,12 +1080,14 @@ static void wcd_correct_swch_plug(struct work_struct *work)
>   	enum wcd_mbhc_plug_type plug_type = MBHC_PLUG_TYPE_INVALID;
>   	unsigned long timeout;
>   	int pt_gnd_mic_swap_cnt = 0;
> -	int output_mv, cross_conn, hs_threshold, try = 0;
> +	int output_mv, cross_conn, hs_threshold, try = 0, micbias_mv;
> +	bool is_spl_hs = false;
>   	bool is_pa_on;
>   
>   	mbhc = container_of(work, struct wcd_mbhc, correct_plug_swch);
>   	component = mbhc->component;
>   
> +	micbias_mv = wcd_mbhc_get_micbias(mbhc);
>   	hs_threshold = wcd_mbhc_adc_get_hs_thres(mbhc);
>   
>   	/* Mask ADC COMPLETE interrupt */
> @@ -1097,6 +1150,18 @@ static void wcd_correct_swch_plug(struct work_struct *work)
>   		plug_type = wcd_mbhc_get_plug_from_adc(mbhc, output_mv);
>   		is_pa_on = wcd_mbhc_read_field(mbhc, WCD_MBHC_HPH_PA_EN);
>   
> +
unnecessary extra new line here.

> +		if ((output_mv > hs_threshold) &&
> +		    (!is_spl_hs)) {
wrap to 100 chars and unneccessary brackets around the conditions.

With those fixed


Reviewed-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>

--srini

> +			is_spl_hs = wcd_mbhc_check_for_spl_headset(mbhc);
> +			output_mv = wcd_measure_adc_once(mbhc, MUX_CTL_IN2P);
> +
> +			if (is_spl_hs) {
> +				hs_threshold = (hs_threshold * wcd_mbhc_get_micbias(mbhc)) /
> +									micbias_mv; > +			}
> +		}
> +
>   		if ((output_mv <= hs_threshold) && !is_pa_on) {
>   			/* Check for cross connection*/
>   			cross_conn = wcd_check_cross_conn(mbhc);
> @@ -1122,14 +1187,19 @@ static void wcd_correct_swch_plug(struct work_struct *work)
>   			}
>   		}
>   
> -		if (output_mv > hs_threshold) /* cable is extension cable */
> +		/* cable is extension cable */
> +		if (output_mv > hs_threshold || mbhc->force_linein == true)
>   			plug_type = MBHC_PLUG_TYPE_HIGH_HPH;
>   	}
>   
>   	wcd_mbhc_bcs_enable(mbhc, plug_type, true);
>   
> -	if (plug_type == MBHC_PLUG_TYPE_HIGH_HPH)
> -		wcd_mbhc_write_field(mbhc, WCD_MBHC_ELECT_ISRC_EN, 1);
> +	if (plug_type == MBHC_PLUG_TYPE_HIGH_HPH) {
> +		if (is_spl_hs)
> +			plug_type = MBHC_PLUG_TYPE_HEADSET;
> +		else
> +			wcd_mbhc_write_field(mbhc, WCD_MBHC_ELECT_ISRC_EN, 1);
> +	}
>   
>   	wcd_mbhc_write_field(mbhc, WCD_MBHC_ADC_MODE, 0);
>   	wcd_mbhc_write_field(mbhc, WCD_MBHC_ADC_EN, 0);
> 

  reply	other threads:[~2021-11-10 10:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 11:18 Srinivasa Rao Mandadapu
2021-11-10 10:12 ` Srinivas Kandagatla [this message]
2021-11-15 23:35 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8422a82f-5aa7-2458-8080-87f330fa63ea@linaro.org \
    --to=srinivas.kandagatla@linaro.org \
    --cc=agross@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=bgoswami@codeaurora.org \
    --cc=bjorn.andersson@linaro.org \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=judyhsiao@chromium.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=plai@codeaurora.org \
    --cc=potturu@codeaurora.org \
    --cc=robh+dt@kernel.org \
    --cc=rohitkr@codeaurora.org \
    --cc=srivasam@codeaurora.org \
    --cc=swboyd@chromium.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®