diff --git a/asoc/codecs/bolero/bolero-cdc.c b/asoc/codecs/bolero/bolero-cdc.c index 8db452930ef1..6f81dab723a6 100644 --- a/asoc/codecs/bolero/bolero-cdc.c +++ b/asoc/codecs/bolero/bolero-cdc.c @@ -501,8 +501,10 @@ int bolero_register_macro(struct device *dev, u16 macro_id, priv->macro_params[macro_id].dev = dev; priv->current_mclk_mux_macro[macro_id] = bolero_mclk_mux_tbl[macro_id][MCLK_MUX0]; - if (macro_id == TX_MACRO) + 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->num_dais += ops->num_dais; priv->num_macros_registered++; @@ -562,8 +564,10 @@ void bolero_unregister_macro(struct device *dev, u16 macro_id) priv->macro_params[macro_id].dai_ptr = NULL; priv->macro_params[macro_id].event_handler = NULL; priv->macro_params[macro_id].dev = NULL; - if (macro_id == TX_MACRO) + if (macro_id == TX_MACRO) { priv->macro_params[macro_id].reg_wake_irq = NULL; + priv->macro_params[macro_id].clk_switch = NULL; + } priv->num_dais -= priv->macro_params[macro_id].num_dais; priv->num_macros_registered--; @@ -768,6 +772,37 @@ 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. + * + * Returns 0 on success or -EINVAL on error. + */ +int bolero_tx_clk_switch(struct snd_soc_component *component) +{ + 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); + + return ret; +} +EXPORT_SYMBOL(bolero_tx_clk_switch); + static int bolero_soc_codec_probe(struct snd_soc_component *component) { struct bolero_priv *priv = dev_get_drvdata(component->dev); diff --git a/asoc/codecs/bolero/bolero-cdc.h b/asoc/codecs/bolero/bolero-cdc.h index 362b521849af..7e8ec83266b6 100644 --- a/asoc/codecs/bolero/bolero-cdc.h +++ b/asoc/codecs/bolero/bolero-cdc.h @@ -55,6 +55,7 @@ struct macro_ops { int (*reg_wake_irq)(struct snd_soc_component *component, u32 data); int (*set_port_map)(struct snd_soc_component *component, u32 uc, u32 size, void *data); + int (*clk_switch)(struct snd_soc_component *component); char __iomem *io_base; u16 clk_id_req; u16 default_clk_id; @@ -78,6 +79,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); #else static inline int bolero_register_res_clk(struct device *dev, rsc_clk_cb_t cb) { @@ -136,5 +138,11 @@ 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) +{ + return 0; +} + #endif /* CONFIG_SND_SOC_BOLERO */ #endif /* BOLERO_CDC_H */ diff --git a/asoc/codecs/bolero/tx-macro.c b/asoc/codecs/bolero/tx-macro.c index 08c185380350..15b089d1f0dd 100644 --- a/asoc/codecs/bolero/tx-macro.c +++ b/asoc/codecs/bolero/tx-macro.c @@ -1660,6 +1660,36 @@ done: return ret; } +static int tx_macro_clk_switch(struct snd_soc_component *component) +{ + 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, NULL); + } + + return ret; +} + static int tx_macro_swrm_clock(void *handle, bool enable) { struct tx_macro_priv *tx_priv = (struct tx_macro_priv *) handle; @@ -2024,6 +2054,7 @@ static void tx_macro_init_ops(struct macro_ops *ops, ops->event_handler = tx_macro_event_handler; ops->reg_wake_irq = tx_macro_reg_wake_irq; ops->set_port_map = tx_macro_set_port_map; + ops->clk_switch = tx_macro_clk_switch; } static int tx_macro_probe(struct platform_device *pdev) diff --git a/asoc/codecs/bolero/va-macro.c b/asoc/codecs/bolero/va-macro.c index 8e5abaa3c7d4..d4dd4e6e6188 100644 --- a/asoc/codecs/bolero/va-macro.c +++ b/asoc/codecs/bolero/va-macro.c @@ -283,8 +283,14 @@ 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)) + dev_dbg(va_dev, "%s: clock switch failed\n", + __func__); break; case SND_SOC_DAPM_POST_PMD: + if (bolero_tx_clk_switch(component)) + dev_dbg(va_dev, "%s: clock switch failed\n",__func__); if (va_priv->lpass_audio_hw_vote) clk_disable_unprepare(va_priv->lpass_audio_hw_vote); break; @@ -311,18 +317,18 @@ static int va_macro_mclk_event(struct snd_soc_dapm_widget *w, dev_dbg(va_dev, "%s: event = %d\n", __func__, event); switch (event) { case SND_SOC_DAPM_PRE_PMU: - ret = va_macro_mclk_enable(va_priv, 1, true); ret = bolero_clk_rsc_request_clock(va_priv->dev, va_priv->default_clk_id, TX_CORE_CLK, true); + ret = va_macro_mclk_enable(va_priv, 1, true); break; case SND_SOC_DAPM_POST_PMD: + va_macro_mclk_enable(va_priv, 0, true); bolero_clk_rsc_request_clock(va_priv->dev, va_priv->default_clk_id, TX_CORE_CLK, false); - va_macro_mclk_enable(va_priv, 0, true); break; default: dev_err(va_priv->dev,