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

Commit ea56a753 authored by Meng Wang's avatar Meng Wang
Browse files

Revert "Revert "ASoC: bolero: check clock source before clock switch""



This reverts commit 68cbba47 as this
causes AMIC SVA issue.

Change-Id: I0e66c97dfc9499c30942ce2e3a123be58833eac8
Signed-off-by: default avatarMeng Wang <mengw@codeaurora.org>
parent b3875954
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -687,6 +687,7 @@ int bolero_register_macro(struct device *dev, u16 macro_id,
				bolero_mclk_mux_tbl[macro_id][MCLK_MUX0];
	if (macro_id == TX_MACRO) {
		priv->macro_params[macro_id].reg_wake_irq = ops->reg_wake_irq;
		priv->macro_params[macro_id].clk_switch = ops->clk_switch;
		priv->macro_params[macro_id].reg_evt_listener =
							ops->reg_evt_listener;
		priv->macro_params[macro_id].clk_enable = ops->clk_enable;
@@ -761,6 +762,7 @@ void bolero_unregister_macro(struct device *dev, u16 macro_id)
	priv->macro_params[macro_id].dev = NULL;
	if (macro_id == TX_MACRO) {
		priv->macro_params[macro_id].reg_wake_irq = NULL;
		priv->macro_params[macro_id].clk_switch = NULL;
		priv->macro_params[macro_id].reg_evt_listener = NULL;
		priv->macro_params[macro_id].clk_enable = NULL;
	}
@@ -1061,6 +1063,40 @@ int bolero_register_wake_irq(struct snd_soc_component *component,
}
EXPORT_SYMBOL(bolero_register_wake_irq);

/**
 * bolero_tx_clk_switch - Switch tx macro clock
 *
 * @component: pointer to codec component instance.
 *
 * @clk_src: 0 for TX_RCG and 1 for VA_RCG
 *
 * Returns 0 on success or -EINVAL on error.
 */
int bolero_tx_clk_switch(struct snd_soc_component *component, int clk_src)
{
	struct bolero_priv *priv = NULL;
	int ret = 0;

	if (!component)
		return -EINVAL;

	priv = snd_soc_component_get_drvdata(component);
	if (!priv)
		return -EINVAL;

	if (!bolero_is_valid_codec_dev(priv->dev)) {
		dev_err(component->dev, "%s: invalid codec\n", __func__);
		return -EINVAL;
	}

	if (priv->macro_params[TX_MACRO].clk_switch)
		ret = priv->macro_params[TX_MACRO].clk_switch(component,
							      clk_src);

	return ret;
}
EXPORT_SYMBOL(bolero_tx_clk_switch);

/**
 * bolero_tx_mclk_enable - Enable/Disable TX Macro mclk
 *
+13 −0
Original line number Diff line number Diff line
@@ -37,6 +37,11 @@ enum {
	BOLERO_ADC_MAX
};

enum {
	CLK_SRC_TX_RCG = 0,
	CLK_SRC_VA_RCG,
};

enum {
	BOLERO_MACRO_EVT_RX_MUTE = 1, /* for RX mute/unmute */
	BOLERO_MACRO_EVT_IMPED_TRUE, /* for imped true */
@@ -74,6 +79,7 @@ struct macro_ops {
	int (*set_port_map)(struct snd_soc_component *component, u32 uc,
			    u32 size, void *data);
	int (*clk_div_get)(struct snd_soc_component *component);
	int (*clk_switch)(struct snd_soc_component *component, int clk_src);
	int (*reg_evt_listener)(struct snd_soc_component *component, bool en);
	int (*clk_enable)(struct snd_soc_component *c, bool en);
	char __iomem *io_base;
@@ -100,6 +106,7 @@ void bolero_clear_amic_tx_hold(struct device *dev, u16 adc_n);
int bolero_runtime_resume(struct device *dev);
int bolero_runtime_suspend(struct device *dev);
int bolero_set_port_map(struct snd_soc_component *component, u32 size, void *data);
int bolero_tx_clk_switch(struct snd_soc_component *component, int clk_src);
int bolero_register_event_listener(struct snd_soc_component *component,
				   bool enable);
void bolero_wsa_pa_on(struct device *dev, bool adie_lb);
@@ -172,6 +179,12 @@ static inline int bolero_set_port_map(struct snd_soc_component *component,
	return 0;
}

static inline int bolero_tx_clk_switch(struct snd_soc_component *component,
					int clk_src)
{
	return 0;
}

static inline int bolero_register_event_listener(
					struct snd_soc_component *component,
					bool enable)
+31 −0
Original line number Diff line number Diff line
@@ -2848,6 +2848,36 @@ static int tx_macro_clk_div_get(struct snd_soc_component *component)
	return tx_priv->dmic_clk_div;
}

static int tx_macro_clk_switch(struct snd_soc_component *component, int clk_src)
{
	struct device *tx_dev = NULL;
	struct tx_macro_priv *tx_priv = NULL;
	int ret = 0;

	if (!component)
		return -EINVAL;

	tx_dev = bolero_get_device_ptr(component->dev, TX_MACRO);
	if (!tx_dev) {
		dev_err(component->dev,
			"%s: null device for macro!\n", __func__);
		return -EINVAL;
	}
	tx_priv = dev_get_drvdata(tx_dev);
	if (!tx_priv) {
		dev_err(component->dev,
			"%s: priv is null for macro!\n", __func__);
		return -EINVAL;
	}
	if (tx_priv->swr_ctrl_data) {
		ret = swrm_wcd_notify(
			tx_priv->swr_ctrl_data[0].tx_swr_pdev,
			SWR_REQ_CLK_SWITCH, &clk_src);
	}

	return ret;
}

static int tx_macro_core_vote(void *handle, bool enable)
{
	struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle;
@@ -3331,6 +3361,7 @@ static void tx_macro_init_ops(struct macro_ops *ops,
	ops->reg_wake_irq = tx_macro_reg_wake_irq;
	ops->set_port_map = tx_macro_set_port_map;
	ops->clk_div_get = tx_macro_clk_div_get;
	ops->clk_switch = tx_macro_clk_switch;
	ops->reg_evt_listener = tx_macro_register_event_listener;
	ops->clk_enable = __tx_macro_mclk_enable;
}
+46 −3
Original line number Diff line number Diff line
@@ -381,6 +381,7 @@ static int va_macro_swr_pwr_event_v2(struct snd_soc_dapm_widget *w,
	int ret = 0;
	struct device *va_dev = NULL;
	struct va_macro_priv *va_priv = NULL;
	int clk_src = 0;

	if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
		return -EINVAL;
@@ -393,12 +394,30 @@ static int va_macro_swr_pwr_event_v2(struct snd_soc_dapm_widget *w,

	switch (event) {
	case SND_SOC_DAPM_PRE_PMU:
		if (va_priv->swr_ctrl_data) {
			clk_src = CLK_SRC_VA_RCG;
			ret = swrm_wcd_notify(
				va_priv->swr_ctrl_data[0].va_swr_pdev,
				SWR_REQ_CLK_SWITCH, &clk_src);
			if (ret)
				dev_dbg(va_dev, "%s: clock switch failed\n",
					__func__);
		}
		msm_cdc_pinctrl_set_wakeup_capable(
				va_priv->va_swr_gpio_p, false);
		break;
	case SND_SOC_DAPM_POST_PMD:
		msm_cdc_pinctrl_set_wakeup_capable(
				va_priv->va_swr_gpio_p, true);
		if (va_priv->swr_ctrl_data) {
			clk_src = CLK_SRC_TX_RCG;
			ret = swrm_wcd_notify(
				va_priv->swr_ctrl_data[0].va_swr_pdev,
				SWR_REQ_CLK_SWITCH, &clk_src);
			if (ret)
				dev_dbg(va_dev, "%s: clock switch failed\n",
					__func__);
		}
		break;
	default:
		dev_err(va_priv->dev,
@@ -436,6 +455,10 @@ static int va_macro_swr_pwr_event(struct snd_soc_dapm_widget *w,
					"%s: lpass audio hw enable failed\n",
					__func__);
		}
		if (!ret)
			if (bolero_tx_clk_switch(component, CLK_SRC_VA_RCG))
				dev_dbg(va_dev, "%s: clock switch failed\n",
					__func__);
		if (va_priv->lpi_enable &&
			!va_priv->disable_afe_wakeup_event_listener) {
			bolero_register_event_listener(component, true);
@@ -447,6 +470,8 @@ static int va_macro_swr_pwr_event(struct snd_soc_dapm_widget *w,
			va_priv->register_event_listener = false;
			bolero_register_event_listener(component, false);
		}
		if (bolero_tx_clk_switch(component, CLK_SRC_TX_RCG))
			dev_dbg(va_dev, "%s: clock switch failed\n",__func__);
		if (va_priv->lpass_audio_hw_vote)
			digital_cdc_rsc_mgr_hw_vote_disable(
				va_priv->lpass_audio_hw_vote);
@@ -486,6 +511,7 @@ static int va_macro_mclk_event(struct snd_soc_dapm_widget *w,
	int ret = 0;
	struct device *va_dev = NULL;
	struct va_macro_priv *va_priv = NULL;
	int clk_src = 0;

	if (!va_macro_get_data(component, &va_dev, &va_priv, __func__))
		return -EINVAL;
@@ -506,10 +532,27 @@ static int va_macro_mclk_event(struct snd_soc_dapm_widget *w,
			ret = bolero_tx_mclk_enable(component, 1);
		break;
	case SND_SOC_DAPM_POST_PMD:
		if (va_priv->lpi_enable)
		if (va_priv->lpi_enable) {
			if (va_priv->version == BOLERO_VERSION_2_1) {
				if (va_priv->swr_ctrl_data) {
					clk_src = CLK_SRC_TX_RCG;
					ret = swrm_wcd_notify(
					va_priv->swr_ctrl_data[0].va_swr_pdev,
					SWR_REQ_CLK_SWITCH, &clk_src);
					if (ret)
						dev_dbg(va_dev,
					"%s: clock switch failed\n",
						__func__);
				}
			} else if (bolero_tx_clk_switch(component,
					CLK_SRC_TX_RCG)) {
				dev_dbg(va_dev, "%s: clock switch failed\n",
					__func__);
			}
			va_macro_mclk_enable(va_priv, 0, true);
		else
		} else {
			bolero_tx_mclk_enable(component, 0);
		}

		if (va_priv->tx_clk_status > 0) {
			bolero_clk_rsc_request_clock(va_priv->dev,