Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5707577c authored by Vatsal Bucha's avatar Vatsal Bucha Committed by Gerrit - the friendly Code Review server
Browse files

ASoC: wcd-mbhc: Resolve warning log when mutex destroy before unlock



Resolve warning log when hph pa mutex lock is destroyed before
unlock. Initialize hph pa locks as global lock and do not destroy
during SSR to resolve issue.

Change-Id: Idc5af793294f7fdc8dbcc17770f68fe2c46ab337
Signed-off-by: default avatarVatsal Bucha <vbucha@codeaurora.org>
parent 2ae270f0
Loading
Loading
Loading
Loading
+15 −18
Original line number Diff line number Diff line
@@ -27,6 +27,9 @@
#include "wcd-mbhc-adc.h"
#include <asoc/wcd-mbhc-v2-api.h>

struct mutex hphl_pa_lock;
struct mutex hphr_pa_lock;

void wcd_mbhc_jack_report(struct wcd_mbhc *mbhc,
			  struct snd_soc_jack *jack, int status, int mask)
{
@@ -312,9 +315,9 @@ static int wcd_event_notify(struct notifier_block *self, unsigned long val,
			mbhc->mbhc_cb->set_cap_mode(component, micbias1, false);
		break;
	case WCD_EVENT_PRE_HPHL_PA_OFF:
		mutex_lock(&mbhc->hphl_pa_lock);
		break;
	case WCD_EVENT_POST_HPHL_PA_OFF:
		mutex_lock(&hphl_pa_lock);
		clear_bit(WCD_MBHC_HPHL_PA_OFF_ACK, &mbhc->hph_pa_dac_state);
#if IS_ENABLED(CONFIG_AUDIO_QGKI)
		if (mbhc->hph_status & SND_JACK_OC_HPHL)
@@ -328,14 +331,13 @@ static int wcd_event_notify(struct notifier_block *self, unsigned long val,
		else
			/* Disable micbias, pullup & enable cs */
			wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_CS);
		if (mutex_is_locked(&mbhc->hphl_pa_lock))
			mutex_unlock(&mbhc->hphl_pa_lock);
		mutex_unlock(&hphl_pa_lock);
		clear_bit(WCD_MBHC_ANC0_OFF_ACK, &mbhc->hph_anc_state);
		break;
	case WCD_EVENT_PRE_HPHR_PA_OFF:
		mutex_lock(&mbhc->hphr_pa_lock);
		break;
	case WCD_EVENT_POST_HPHR_PA_OFF:
		mutex_lock(&hphr_pa_lock);
		clear_bit(WCD_MBHC_HPHR_PA_OFF_ACK, &mbhc->hph_pa_dac_state);
#if IS_ENABLED(CONFIG_AUDIO_QGKI)
		if (mbhc->hph_status & SND_JACK_OC_HPHR)
@@ -349,8 +351,7 @@ static int wcd_event_notify(struct notifier_block *self, unsigned long val,
		else
			/* Disable micbias, pullup & enable cs */
			wcd_enable_curr_micbias(mbhc, WCD_MBHC_EN_CS);
		if (mutex_is_locked(&mbhc->hphr_pa_lock))
			mutex_unlock(&mbhc->hphr_pa_lock);
		mutex_unlock(&hphr_pa_lock);
		clear_bit(WCD_MBHC_ANC1_OFF_ACK, &mbhc->hph_anc_state);
		break;
	case WCD_EVENT_PRE_HPHL_PA_ON:
@@ -421,22 +422,22 @@ static void wcd_mbhc_clr_and_turnon_hph_padac(struct wcd_mbhc *mbhc)
	WCD_MBHC_REG_READ(WCD_MBHC_HPH_CNP_WG_TIME, wg_time);
	wg_time += 1;

	mutex_lock(&mbhc->hphr_pa_lock);
	mutex_lock(&hphr_pa_lock);
	if (test_and_clear_bit(WCD_MBHC_HPHR_PA_OFF_ACK,
			       &mbhc->hph_pa_dac_state)) {
		pr_debug("%s: HPHR clear flag and enable PA\n", __func__);
		WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_HPHR_PA_EN, 1);
		pa_turned_on = true;
	}
	mutex_unlock(&mbhc->hphr_pa_lock);
	mutex_lock(&mbhc->hphl_pa_lock);
	mutex_unlock(&hphr_pa_lock);
	mutex_lock(&hphl_pa_lock);
	if (test_and_clear_bit(WCD_MBHC_HPHL_PA_OFF_ACK,
			       &mbhc->hph_pa_dac_state)) {
		pr_debug("%s: HPHL clear flag and enable PA\n", __func__);
		WCD_MBHC_REG_UPDATE_BITS(WCD_MBHC_HPHL_PA_EN, 1);
		pa_turned_on = true;
	}
	mutex_unlock(&mbhc->hphl_pa_lock);
	mutex_unlock(&hphl_pa_lock);

	if (pa_turned_on) {
		pr_debug("%s: PA was turned on by MBHC and not by DAPM\n",
@@ -1897,8 +1898,6 @@ int wcd_mbhc_init(struct wcd_mbhc *mbhc, struct snd_soc_component *component,
				  wcd_mbhc_fw_read);
		INIT_DELAYED_WORK(&mbhc->mbhc_btn_dwork, wcd_btn_lpress_fn);
	}
	mutex_init(&mbhc->hphl_pa_lock);
	mutex_init(&mbhc->hphr_pa_lock);
	init_completion(&mbhc->btn_press_compl);

	/* Register event notifier */
@@ -2069,22 +2068,20 @@ void wcd_mbhc_deinit(struct wcd_mbhc *mbhc)
		WCD_MBHC_RSC_UNLOCK(mbhc);
	}
	mutex_destroy(&mbhc->codec_resource_lock);
	if (mutex_is_locked(&mbhc->hphl_pa_lock))
		mutex_unlock(&mbhc->hphl_pa_lock);
	if (mutex_is_locked(&mbhc->hphr_pa_lock))
		mutex_unlock(&mbhc->hphr_pa_lock);
	mutex_destroy(&mbhc->hphl_pa_lock);
	mutex_destroy(&mbhc->hphr_pa_lock);
}
EXPORT_SYMBOL(wcd_mbhc_deinit);

static int __init mbhc_init(void)
{
	mutex_init(&hphl_pa_lock);
	mutex_init(&hphr_pa_lock);
	return 0;
}

static void __exit mbhc_exit(void)
{
	mutex_destroy(&hphl_pa_lock);
	mutex_destroy(&hphr_pa_lock);
}

module_init(mbhc_init);
+1 −3
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (c) 2014-2020, The Linux Foundation. All rights reserved.
/* Copyright (c) 2014-2021, The Linux Foundation. All rights reserved.
 */
#ifndef __WCD_MBHC_V2_H__
#define __WCD_MBHC_V2_H__
@@ -607,8 +607,6 @@ struct wcd_mbhc {
	struct wcd_mbhc_register *wcd_mbhc_regs;

	struct completion btn_press_compl;
	struct mutex hphl_pa_lock;
	struct mutex hphr_pa_lock;
	bool deinit_in_progress;

	/* Holds mbhc detection method - ADC/Legacy */