ASoC: codecs: pm4125: remove duplicate code

With recent addition of wcd-common, lot of code duplication in
pm4125 codec can be removed now.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>
Link: https://patch.msgid.link/20251014153541.283899-1-srinivas.kandagatla@oss.qualcomm.com
Signed-off-by: Mark Brown <broonie@kernel.org>
pull/1354/merge
Srinivas Kandagatla 2025-10-14 16:35:41 +01:00 committed by Mark Brown
parent 4db4ce1570
commit 6951be397c
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
4 changed files with 25 additions and 130 deletions

View File

@ -1595,6 +1595,7 @@ config SND_SOC_PEB2466
config SND_SOC_PM4125
depends on SND_SOC_PM4125_SDW
select SND_SOC_WCD_COMMON
tristate
depends on SOUNDWIRE || !SOUNDWIRE
@ -1603,6 +1604,7 @@ config SND_SOC_PM4125_SDW
select SND_SOC_PM4125
select SND_SOC_WCD_MBHC
select REGMAP_IRQ
select SND_SOC_WCD_COMMON
depends on SOUNDWIRE
select REGMAP_SOUNDWIRE
help

View File

@ -20,12 +20,12 @@
#include <sound/soc.h>
#include "pm4125.h"
static struct pm4125_sdw_ch_info pm4125_sdw_rx_ch_info[] = {
static struct wcd_sdw_ch_info pm4125_sdw_rx_ch_info[] = {
WCD_SDW_CH(PM4125_HPH_L, PM4125_HPH_PORT, BIT(0)),
WCD_SDW_CH(PM4125_HPH_R, PM4125_HPH_PORT, BIT(1)),
};
static struct pm4125_sdw_ch_info pm4125_sdw_tx_ch_info[] = {
static struct wcd_sdw_ch_info pm4125_sdw_tx_ch_info[] = {
WCD_SDW_CH(PM4125_ADC1, PM4125_ADC_1_2_DMIC1L_BCS_PORT, BIT(0)),
WCD_SDW_CH(PM4125_ADC2, PM4125_ADC_1_2_DMIC1L_BCS_PORT, BIT(1)),
};
@ -46,12 +46,6 @@ static struct sdw_dpn_prop pm4125_dpn_prop[PM4125_MAX_SWR_PORTS] = {
}
};
struct device *pm4125_sdw_device_get(struct device_node *np)
{
return bus_find_device_by_of_node(&sdw_bus_type, np);
}
EXPORT_SYMBOL_GPL(pm4125_sdw_device_get);
int pm4125_sdw_hw_params(struct pm4125_sdw_priv *priv, struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
{
@ -83,19 +77,6 @@ int pm4125_sdw_hw_params(struct pm4125_sdw_priv *priv, struct snd_pcm_substream
}
EXPORT_SYMBOL_GPL(pm4125_sdw_hw_params);
static int pm4125_update_status(struct sdw_slave *slave, enum sdw_slave_status status)
{
struct pm4125_sdw_priv *priv = dev_get_drvdata(&slave->dev);
if (priv->regmap && status == SDW_SLAVE_ATTACHED) {
/* Write out any cached changes that happened between probe and attach */
regcache_cache_only(priv->regmap, false);
return regcache_sync(priv->regmap);
}
return 0;
}
/*
* Handle Soundwire out-of-band interrupt event by triggering the first irq of the slave_irq
* irq domain, which then will be handled by the regmap_irq threaded irq.
@ -104,18 +85,9 @@ static int pm4125_update_status(struct sdw_slave *slave, enum sdw_slave_status s
static int pm4125_interrupt_callback(struct sdw_slave *slave, struct sdw_slave_intr_status *status)
{
struct pm4125_sdw_priv *priv = dev_get_drvdata(&slave->dev);
struct irq_domain *slave_irq = priv->slave_irq;
u32 sts1, sts2, sts3;
do {
handle_nested_irq(irq_find_mapping(slave_irq, 0));
regmap_read(priv->regmap, PM4125_DIG_SWR_INTR_STATUS_0, &sts1);
regmap_read(priv->regmap, PM4125_DIG_SWR_INTR_STATUS_1, &sts2);
regmap_read(priv->regmap, PM4125_DIG_SWR_INTR_STATUS_2, &sts3);
} while (sts1 || sts2 || sts3);
return IRQ_HANDLED;
return wcd_interrupt_callback(slave, priv->slave_irq, PM4125_DIG_SWR_INTR_STATUS_0,
PM4125_DIG_SWR_INTR_STATUS_1, PM4125_DIG_SWR_INTR_STATUS_2);
}
static const struct reg_default pm4125_defaults[] = {
@ -369,32 +341,10 @@ static const struct regmap_config pm4125_regmap_config = {
};
static const struct sdw_slave_ops pm4125_slave_ops = {
.update_status = pm4125_update_status,
.update_status = wcd_update_status,
.interrupt_callback = pm4125_interrupt_callback,
};
static int pm4125_sdw_component_bind(struct device *dev, struct device *master, void *data)
{
pm_runtime_set_autosuspend_delay(dev, 3000);
pm_runtime_use_autosuspend(dev);
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
return 0;
}
static void pm4125_sdw_component_unbind(struct device *dev, struct device *master, void *data)
{
pm_runtime_disable(dev);
pm_runtime_set_suspended(dev);
pm_runtime_dont_use_autosuspend(dev);
}
static const struct component_ops pm4125_sdw_component_ops = {
.bind = pm4125_sdw_component_bind,
.unbind = pm4125_sdw_component_unbind,
};
static int pm4125_probe(struct sdw_slave *pdev, const struct sdw_device_id *id)
{
struct device *dev = &pdev->dev;
@ -476,7 +426,7 @@ static int pm4125_probe(struct sdw_slave *pdev, const struct sdw_device_id *id)
priv->ch_info[i].master_ch_mask = PM4125_SWRM_CH_MASK(master_ch_mask[i]);
}
ret = component_add(dev, &pm4125_sdw_component_ops);
ret = component_add(dev, &wcd_sdw_component_ops);
if (ret)
return ret;
@ -490,7 +440,7 @@ static int pm4125_remove(struct sdw_slave *pdev)
{
struct device *dev = &pdev->dev;
component_del(dev, &pm4125_sdw_component_ops);
component_del(dev, &wcd_sdw_component_ops);
return 0;
}

View File

@ -69,6 +69,7 @@ struct pm4125_priv {
struct wcd_mbhc *wcd_mbhc;
struct wcd_mbhc_config mbhc_cfg;
struct wcd_mbhc_intr intr_ids;
struct wcd_common common;
struct irq_domain *virq;
const struct regmap_irq_chip *pm4125_regmap_irq_chip;
struct regmap_irq_chip_data *irq_chip;
@ -76,9 +77,6 @@ struct pm4125_priv {
unsigned long status_mask;
s32 micb_ref[PM4125_MAX_MICBIAS];
s32 pullup_ref[PM4125_MAX_MICBIAS];
u32 micb1_mv;
u32 micb2_mv;
u32 micb3_mv;
int hphr_pdm_wd_int;
int hphl_pdm_wd_int;
@ -644,16 +642,6 @@ static int pm4125_codec_enable_ear_pa(struct snd_soc_dapm_widget *w,
return 0;
}
static int pm4125_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv)
{
if (micb_mv < 1600 || micb_mv > 2850) {
dev_err(dev, "%s: unsupported micbias voltage (%u mV)\n", __func__, micb_mv);
return -EINVAL;
}
return (micb_mv - 1600) / 50;
}
static int pm4125_codec_enable_adc(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol, int event)
{
@ -855,7 +843,7 @@ static int pm4125_codec_enable_micbias_pullup(struct snd_soc_dapm_widget *w,
static int pm4125_connect_port(struct pm4125_sdw_priv *sdw_priv, u8 port_idx, u8 ch_id, bool enable)
{
struct sdw_port_config *port_config = &sdw_priv->port_config[port_idx - 1];
const struct pm4125_sdw_ch_info *ch_info = &sdw_priv->ch_info[ch_id];
const struct wcd_sdw_ch_info *ch_info = &sdw_priv->ch_info[ch_id];
struct sdw_slave *sdev = sdw_priv->sdev;
u8 port_num = ch_info->port_num;
u8 ch_mask = ch_info->ch_mask;
@ -1266,15 +1254,8 @@ static const struct snd_soc_dapm_route pm4125_audio_map[] = {
static int pm4125_set_micbias_data(struct device *dev, struct pm4125_priv *pm4125)
{
int vout_ctl;
/* Set micbias voltage */
vout_ctl = pm4125_get_micb_vout_ctl_val(dev, pm4125->micb1_mv);
if (vout_ctl < 0)
return -EINVAL;
regmap_update_bits(pm4125->regmap, PM4125_ANA_MICBIAS_LDO_1_SETTING,
PM4125_ANA_MICBIAS_MICB_OUT_VAL_MASK, vout_ctl << 3);
PM4125_ANA_MICBIAS_MICB_OUT_VAL_MASK, pm4125->common.micb_vout[0]);
return 0;
}
@ -1418,31 +1399,6 @@ static const struct snd_soc_component_driver soc_codec_dev_pm4125 = {
.endianness = 1,
};
static void pm4125_dt_parse_micbias_info(struct device *dev, struct pm4125_priv *priv)
{
struct device_node *np = dev->of_node;
u32 prop_val = 0;
int ret;
ret = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val);
if (!ret)
priv->micb1_mv = prop_val / 1000;
else
dev_warn(dev, "Micbias1 DT property not found\n");
ret = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val);
if (!ret)
priv->micb2_mv = prop_val / 1000;
else
dev_warn(dev, "Micbias2 DT property not found\n");
ret = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val);
if (!ret)
priv->micb3_mv = prop_val / 1000;
else
dev_warn(dev, "Micbias3 DT property not found\n");
}
static int pm4125_codec_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
@ -1560,7 +1516,7 @@ static int pm4125_bind(struct device *dev)
return ret;
}
pm4125->rxdev = pm4125_sdw_device_get(pm4125->rxnode);
pm4125->rxdev = of_sdw_find_device_by_node(pm4125->rxnode);
if (!pm4125->rxdev) {
dev_err(dev, "could not find rxslave with matching of node\n");
ret = -EINVAL;
@ -1570,7 +1526,7 @@ static int pm4125_bind(struct device *dev)
pm4125->sdw_priv[AIF1_PB] = dev_get_drvdata(pm4125->rxdev);
pm4125->sdw_priv[AIF1_PB]->pm4125 = pm4125;
pm4125->txdev = pm4125_sdw_device_get(pm4125->txnode);
pm4125->txdev = of_sdw_find_device_by_node(pm4125->txnode);
if (!pm4125->txdev) {
dev_err(dev, "could not find txslave with matching of node\n");
ret = -EINVAL;
@ -1615,7 +1571,7 @@ static int pm4125_bind(struct device *dev)
goto link_remove_dev_tx;
}
pm4125->regmap = dev_get_regmap(&pm4125->tx_sdw_dev->dev, NULL);
pm4125->regmap = pm4125->sdw_priv[AIF1_CAP]->regmap;
if (!pm4125->regmap) {
dev_err(dev, "could not get TX device regmap\n");
ret = -EINVAL;
@ -1631,11 +1587,7 @@ static int pm4125_bind(struct device *dev)
pm4125->sdw_priv[AIF1_PB]->slave_irq = pm4125->virq;
pm4125->sdw_priv[AIF1_CAP]->slave_irq = pm4125->virq;
ret = pm4125_set_micbias_data(dev, pm4125);
if (ret < 0) {
dev_err(dev, "Bad micbias pdata\n");
goto link_remove_dev_rx;
}
pm4125_set_micbias_data(dev, pm4125);
ret = snd_soc_register_component(dev, &soc_codec_dev_pm4125,
pm4125_dais, ARRAY_SIZE(pm4125_dais));
@ -1716,7 +1668,12 @@ static int pm4125_probe(struct platform_device *pdev)
pm4125_reset(pm4125);
pm4125_dt_parse_micbias_info(dev, pm4125);
pm4125->common.dev = dev;
pm4125->common.max_bias = 3;
ret = wcd_dt_parse_micbias_info(&pm4125->common);
if (ret)
return dev_err_probe(dev, ret, "Failed to get micbias\n");
atomic_set(&pm4125->gloal_mbias_cnt, 0);
cfg = &pm4125->mbhc_cfg;
@ -1724,7 +1681,7 @@ static int pm4125_probe(struct platform_device *pdev)
cfg->anc_micbias = MIC_BIAS_2;
cfg->v_hs_max = WCD_MBHC_HS_V_MAX;
cfg->num_btn = PM4125_MBHC_MAX_BUTTONS;
cfg->micb_mv = pm4125->micb2_mv;
cfg->micb_mv = pm4125->common.micb_mv[1];
cfg->linein_th = 5000;
cfg->hs_thr = 1700;
cfg->hph_thr = 50;

View File

@ -7,6 +7,7 @@
#include <linux/soundwire/sdw.h>
#include <linux/soundwire/sdw_type.h>
#include "wcd-common.h"
#define PM4125_ANA_BASE_ADDR 0x3000
#define PM4125_DIG_BASE_ADDR 0x3400
@ -202,26 +203,13 @@ enum pm4125_rx_sdw_ports {
PM4125_MAX_SWR_PORTS = PM4125_COMP_PORT,
};
struct pm4125_sdw_ch_info {
int port_num;
unsigned int ch_mask;
unsigned int master_ch_mask;
};
#define WCD_SDW_CH(id, pn, cmask) \
[id] = { \
.port_num = pn, \
.ch_mask = cmask, \
.master_ch_mask = cmask, \
}
struct pm4125_priv;
struct pm4125_sdw_priv {
struct sdw_slave *sdev;
struct sdw_stream_config sconfig;
struct sdw_stream_runtime *sruntime;
struct sdw_port_config port_config[PM4125_MAX_SWR_PORTS];
struct pm4125_sdw_ch_info *ch_info;
struct wcd_sdw_ch_info *ch_info;
bool port_enable[PM4125_MAX_SWR_CH_IDS];
unsigned int master_channel_map[SDW_MAX_PORTS];
int active_ports;
@ -240,8 +228,6 @@ int pm4125_sdw_set_sdw_stream(struct pm4125_sdw_priv *pm4125, struct snd_soc_dai
int pm4125_sdw_hw_params(struct pm4125_sdw_priv *pm4125, struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params, struct snd_soc_dai *dai);
struct device *pm4125_sdw_device_get(struct device_node *np);
#else
static inline int pm4125_sdw_free(struct pm4125_sdw_priv *pm4125,
struct snd_pcm_substream *substream, struct snd_soc_dai *dai)