Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Srinivas Kandagatla and committed by
Mark Brown
6951be39 4db4ce15

+25 -130
+2
sound/soc/codecs/Kconfig
··· 1595 1595 1596 1596 config SND_SOC_PM4125 1597 1597 depends on SND_SOC_PM4125_SDW 1598 + select SND_SOC_WCD_COMMON 1598 1599 tristate 1599 1600 depends on SOUNDWIRE || !SOUNDWIRE 1600 1601 ··· 1604 1603 select SND_SOC_PM4125 1605 1604 select SND_SOC_WCD_MBHC 1606 1605 select REGMAP_IRQ 1606 + select SND_SOC_WCD_COMMON 1607 1607 depends on SOUNDWIRE 1608 1608 select REGMAP_SOUNDWIRE 1609 1609 help
+7 -57
sound/soc/codecs/pm4125-sdw.c
··· 20 20 #include <sound/soc.h> 21 21 #include "pm4125.h" 22 22 23 - static struct pm4125_sdw_ch_info pm4125_sdw_rx_ch_info[] = { 23 + static struct wcd_sdw_ch_info pm4125_sdw_rx_ch_info[] = { 24 24 WCD_SDW_CH(PM4125_HPH_L, PM4125_HPH_PORT, BIT(0)), 25 25 WCD_SDW_CH(PM4125_HPH_R, PM4125_HPH_PORT, BIT(1)), 26 26 }; 27 27 28 - static struct pm4125_sdw_ch_info pm4125_sdw_tx_ch_info[] = { 28 + static struct wcd_sdw_ch_info pm4125_sdw_tx_ch_info[] = { 29 29 WCD_SDW_CH(PM4125_ADC1, PM4125_ADC_1_2_DMIC1L_BCS_PORT, BIT(0)), 30 30 WCD_SDW_CH(PM4125_ADC2, PM4125_ADC_1_2_DMIC1L_BCS_PORT, BIT(1)), 31 31 }; ··· 45 45 .simple_ch_prep_sm = true, 46 46 } 47 47 }; 48 - 49 - struct device *pm4125_sdw_device_get(struct device_node *np) 50 - { 51 - return bus_find_device_by_of_node(&sdw_bus_type, np); 52 - } 53 - EXPORT_SYMBOL_GPL(pm4125_sdw_device_get); 54 48 55 49 int pm4125_sdw_hw_params(struct pm4125_sdw_priv *priv, struct snd_pcm_substream *substream, 56 50 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) ··· 77 83 } 78 84 EXPORT_SYMBOL_GPL(pm4125_sdw_hw_params); 79 85 80 - static int pm4125_update_status(struct sdw_slave *slave, enum sdw_slave_status status) 81 - { 82 - struct pm4125_sdw_priv *priv = dev_get_drvdata(&slave->dev); 83 - 84 - if (priv->regmap && status == SDW_SLAVE_ATTACHED) { 85 - /* Write out any cached changes that happened between probe and attach */ 86 - regcache_cache_only(priv->regmap, false); 87 - return regcache_sync(priv->regmap); 88 - } 89 - 90 - return 0; 91 - } 92 - 93 86 /* 94 87 * Handle Soundwire out-of-band interrupt event by triggering the first irq of the slave_irq 95 88 * irq domain, which then will be handled by the regmap_irq threaded irq. ··· 85 104 static int pm4125_interrupt_callback(struct sdw_slave *slave, struct sdw_slave_intr_status *status) 86 105 { 87 106 struct pm4125_sdw_priv *priv = dev_get_drvdata(&slave->dev); 88 - struct irq_domain *slave_irq = priv->slave_irq; 89 - u32 sts1, sts2, sts3; 90 107 91 - do { 92 - handle_nested_irq(irq_find_mapping(slave_irq, 0)); 93 - regmap_read(priv->regmap, PM4125_DIG_SWR_INTR_STATUS_0, &sts1); 94 - regmap_read(priv->regmap, PM4125_DIG_SWR_INTR_STATUS_1, &sts2); 95 - regmap_read(priv->regmap, PM4125_DIG_SWR_INTR_STATUS_2, &sts3); 96 - 97 - } while (sts1 || sts2 || sts3); 98 - 99 - return IRQ_HANDLED; 108 + return wcd_interrupt_callback(slave, priv->slave_irq, PM4125_DIG_SWR_INTR_STATUS_0, 109 + PM4125_DIG_SWR_INTR_STATUS_1, PM4125_DIG_SWR_INTR_STATUS_2); 100 110 } 101 111 102 112 static const struct reg_default pm4125_defaults[] = { ··· 341 369 }; 342 370 343 371 static const struct sdw_slave_ops pm4125_slave_ops = { 344 - .update_status = pm4125_update_status, 372 + .update_status = wcd_update_status, 345 373 .interrupt_callback = pm4125_interrupt_callback, 346 - }; 347 - 348 - static int pm4125_sdw_component_bind(struct device *dev, struct device *master, void *data) 349 - { 350 - pm_runtime_set_autosuspend_delay(dev, 3000); 351 - pm_runtime_use_autosuspend(dev); 352 - pm_runtime_set_active(dev); 353 - pm_runtime_enable(dev); 354 - 355 - return 0; 356 - } 357 - 358 - static void pm4125_sdw_component_unbind(struct device *dev, struct device *master, void *data) 359 - { 360 - pm_runtime_disable(dev); 361 - pm_runtime_set_suspended(dev); 362 - pm_runtime_dont_use_autosuspend(dev); 363 - } 364 - 365 - static const struct component_ops pm4125_sdw_component_ops = { 366 - .bind = pm4125_sdw_component_bind, 367 - .unbind = pm4125_sdw_component_unbind, 368 374 }; 369 375 370 376 static int pm4125_probe(struct sdw_slave *pdev, const struct sdw_device_id *id) ··· 426 476 priv->ch_info[i].master_ch_mask = PM4125_SWRM_CH_MASK(master_ch_mask[i]); 427 477 } 428 478 429 - ret = component_add(dev, &pm4125_sdw_component_ops); 479 + ret = component_add(dev, &wcd_sdw_component_ops); 430 480 if (ret) 431 481 return ret; 432 482 ··· 440 490 { 441 491 struct device *dev = &pdev->dev; 442 492 443 - component_del(dev, &pm4125_sdw_component_ops); 493 + component_del(dev, &wcd_sdw_component_ops); 444 494 445 495 return 0; 446 496 }
+14 -57
sound/soc/codecs/pm4125.c
··· 69 69 struct wcd_mbhc *wcd_mbhc; 70 70 struct wcd_mbhc_config mbhc_cfg; 71 71 struct wcd_mbhc_intr intr_ids; 72 + struct wcd_common common; 72 73 struct irq_domain *virq; 73 74 const struct regmap_irq_chip *pm4125_regmap_irq_chip; 74 75 struct regmap_irq_chip_data *irq_chip; ··· 77 76 unsigned long status_mask; 78 77 s32 micb_ref[PM4125_MAX_MICBIAS]; 79 78 s32 pullup_ref[PM4125_MAX_MICBIAS]; 80 - u32 micb1_mv; 81 - u32 micb2_mv; 82 - u32 micb3_mv; 83 79 84 80 int hphr_pdm_wd_int; 85 81 int hphl_pdm_wd_int; ··· 642 644 return 0; 643 645 } 644 646 645 - static int pm4125_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv) 646 - { 647 - if (micb_mv < 1600 || micb_mv > 2850) { 648 - dev_err(dev, "%s: unsupported micbias voltage (%u mV)\n", __func__, micb_mv); 649 - return -EINVAL; 650 - } 651 - 652 - return (micb_mv - 1600) / 50; 653 - } 654 - 655 647 static int pm4125_codec_enable_adc(struct snd_soc_dapm_widget *w, 656 648 struct snd_kcontrol *kcontrol, int event) 657 649 { ··· 843 855 static int pm4125_connect_port(struct pm4125_sdw_priv *sdw_priv, u8 port_idx, u8 ch_id, bool enable) 844 856 { 845 857 struct sdw_port_config *port_config = &sdw_priv->port_config[port_idx - 1]; 846 - const struct pm4125_sdw_ch_info *ch_info = &sdw_priv->ch_info[ch_id]; 858 + const struct wcd_sdw_ch_info *ch_info = &sdw_priv->ch_info[ch_id]; 847 859 struct sdw_slave *sdev = sdw_priv->sdev; 848 860 u8 port_num = ch_info->port_num; 849 861 u8 ch_mask = ch_info->ch_mask; ··· 1254 1266 1255 1267 static int pm4125_set_micbias_data(struct device *dev, struct pm4125_priv *pm4125) 1256 1268 { 1257 - int vout_ctl; 1258 - 1259 - /* Set micbias voltage */ 1260 - vout_ctl = pm4125_get_micb_vout_ctl_val(dev, pm4125->micb1_mv); 1261 - if (vout_ctl < 0) 1262 - return -EINVAL; 1263 - 1264 1269 regmap_update_bits(pm4125->regmap, PM4125_ANA_MICBIAS_LDO_1_SETTING, 1265 - PM4125_ANA_MICBIAS_MICB_OUT_VAL_MASK, vout_ctl << 3); 1270 + PM4125_ANA_MICBIAS_MICB_OUT_VAL_MASK, pm4125->common.micb_vout[0]); 1266 1271 return 0; 1267 1272 } 1268 1273 ··· 1399 1418 .endianness = 1, 1400 1419 }; 1401 1420 1402 - static void pm4125_dt_parse_micbias_info(struct device *dev, struct pm4125_priv *priv) 1403 - { 1404 - struct device_node *np = dev->of_node; 1405 - u32 prop_val = 0; 1406 - int ret; 1407 - 1408 - ret = of_property_read_u32(np, "qcom,micbias1-microvolt", &prop_val); 1409 - if (!ret) 1410 - priv->micb1_mv = prop_val / 1000; 1411 - else 1412 - dev_warn(dev, "Micbias1 DT property not found\n"); 1413 - 1414 - ret = of_property_read_u32(np, "qcom,micbias2-microvolt", &prop_val); 1415 - if (!ret) 1416 - priv->micb2_mv = prop_val / 1000; 1417 - else 1418 - dev_warn(dev, "Micbias2 DT property not found\n"); 1419 - 1420 - ret = of_property_read_u32(np, "qcom,micbias3-microvolt", &prop_val); 1421 - if (!ret) 1422 - priv->micb3_mv = prop_val / 1000; 1423 - else 1424 - dev_warn(dev, "Micbias3 DT property not found\n"); 1425 - } 1426 - 1427 1421 static int pm4125_codec_hw_params(struct snd_pcm_substream *substream, 1428 1422 struct snd_pcm_hw_params *params, 1429 1423 struct snd_soc_dai *dai) ··· 1516 1560 return ret; 1517 1561 } 1518 1562 1519 - pm4125->rxdev = pm4125_sdw_device_get(pm4125->rxnode); 1563 + pm4125->rxdev = of_sdw_find_device_by_node(pm4125->rxnode); 1520 1564 if (!pm4125->rxdev) { 1521 1565 dev_err(dev, "could not find rxslave with matching of node\n"); 1522 1566 ret = -EINVAL; ··· 1526 1570 pm4125->sdw_priv[AIF1_PB] = dev_get_drvdata(pm4125->rxdev); 1527 1571 pm4125->sdw_priv[AIF1_PB]->pm4125 = pm4125; 1528 1572 1529 - pm4125->txdev = pm4125_sdw_device_get(pm4125->txnode); 1573 + pm4125->txdev = of_sdw_find_device_by_node(pm4125->txnode); 1530 1574 if (!pm4125->txdev) { 1531 1575 dev_err(dev, "could not find txslave with matching of node\n"); 1532 1576 ret = -EINVAL; ··· 1571 1615 goto link_remove_dev_tx; 1572 1616 } 1573 1617 1574 - pm4125->regmap = dev_get_regmap(&pm4125->tx_sdw_dev->dev, NULL); 1618 + pm4125->regmap = pm4125->sdw_priv[AIF1_CAP]->regmap; 1575 1619 if (!pm4125->regmap) { 1576 1620 dev_err(dev, "could not get TX device regmap\n"); 1577 1621 ret = -EINVAL; ··· 1587 1631 pm4125->sdw_priv[AIF1_PB]->slave_irq = pm4125->virq; 1588 1632 pm4125->sdw_priv[AIF1_CAP]->slave_irq = pm4125->virq; 1589 1633 1590 - ret = pm4125_set_micbias_data(dev, pm4125); 1591 - if (ret < 0) { 1592 - dev_err(dev, "Bad micbias pdata\n"); 1593 - goto link_remove_dev_rx; 1594 - } 1634 + pm4125_set_micbias_data(dev, pm4125); 1595 1635 1596 1636 ret = snd_soc_register_component(dev, &soc_codec_dev_pm4125, 1597 1637 pm4125_dais, ARRAY_SIZE(pm4125_dais)); ··· 1668 1716 1669 1717 pm4125_reset(pm4125); 1670 1718 1671 - pm4125_dt_parse_micbias_info(dev, pm4125); 1719 + pm4125->common.dev = dev; 1720 + pm4125->common.max_bias = 3; 1721 + ret = wcd_dt_parse_micbias_info(&pm4125->common); 1722 + if (ret) 1723 + return dev_err_probe(dev, ret, "Failed to get micbias\n"); 1724 + 1672 1725 atomic_set(&pm4125->gloal_mbias_cnt, 0); 1673 1726 1674 1727 cfg = &pm4125->mbhc_cfg; ··· 1681 1724 cfg->anc_micbias = MIC_BIAS_2; 1682 1725 cfg->v_hs_max = WCD_MBHC_HS_V_MAX; 1683 1726 cfg->num_btn = PM4125_MBHC_MAX_BUTTONS; 1684 - cfg->micb_mv = pm4125->micb2_mv; 1727 + cfg->micb_mv = pm4125->common.micb_mv[1]; 1685 1728 cfg->linein_th = 5000; 1686 1729 cfg->hs_thr = 1700; 1687 1730 cfg->hph_thr = 50;
+2 -16
sound/soc/codecs/pm4125.h
··· 7 7 8 8 #include <linux/soundwire/sdw.h> 9 9 #include <linux/soundwire/sdw_type.h> 10 + #include "wcd-common.h" 10 11 11 12 #define PM4125_ANA_BASE_ADDR 0x3000 12 13 #define PM4125_DIG_BASE_ADDR 0x3400 ··· 203 202 PM4125_MAX_SWR_PORTS = PM4125_COMP_PORT, 204 203 }; 205 204 206 - struct pm4125_sdw_ch_info { 207 - int port_num; 208 - unsigned int ch_mask; 209 - unsigned int master_ch_mask; 210 - }; 211 - 212 - #define WCD_SDW_CH(id, pn, cmask) \ 213 - [id] = { \ 214 - .port_num = pn, \ 215 - .ch_mask = cmask, \ 216 - .master_ch_mask = cmask, \ 217 - } 218 - 219 205 struct pm4125_priv; 220 206 struct pm4125_sdw_priv { 221 207 struct sdw_slave *sdev; 222 208 struct sdw_stream_config sconfig; 223 209 struct sdw_stream_runtime *sruntime; 224 210 struct sdw_port_config port_config[PM4125_MAX_SWR_PORTS]; 225 - struct pm4125_sdw_ch_info *ch_info; 211 + struct wcd_sdw_ch_info *ch_info; 226 212 bool port_enable[PM4125_MAX_SWR_CH_IDS]; 227 213 unsigned int master_channel_map[SDW_MAX_PORTS]; 228 214 int active_ports; ··· 227 239 int direction); 228 240 int pm4125_sdw_hw_params(struct pm4125_sdw_priv *pm4125, struct snd_pcm_substream *substream, 229 241 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai); 230 - 231 - struct device *pm4125_sdw_device_get(struct device_node *np); 232 242 233 243 #else 234 244 static inline int pm4125_sdw_free(struct pm4125_sdw_priv *pm4125,