Skip to content

Commit ebaf88c

Browse files
Srinivas Kandagatlabroonie
authored andcommitted
ASoC: codecs: wcd-common: move component ops to common
component_ops for wcd97x, wcd938x, wcd939x soundwire codecs are exactly identlical, move them to common driver to remove this duplicate code. Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com> Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com> Link: https://patch.msgid.link/20250909121954.225833-10-srinivas.kandagatla@oss.qualcomm.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 4652f02 commit ebaf88c

5 files changed

Lines changed: 34 additions & 72 deletions

File tree

sound/soc/codecs/wcd-common.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <linux/device.h>
88
#include <linux/of.h>
99
#include <linux/printk.h>
10+
#include <linux/component.h>
11+
#include <linux/pm_runtime.h>
1012

1113
#include "wcd-common.h"
1214

@@ -66,5 +68,30 @@ int wcd_dt_parse_micbias_info(struct wcd_common *common)
6668
return 0;
6769
}
6870
EXPORT_SYMBOL_GPL(wcd_dt_parse_micbias_info);
71+
72+
static int wcd_sdw_component_bind(struct device *dev, struct device *master, void *data)
73+
{
74+
pm_runtime_set_autosuspend_delay(dev, 3000);
75+
pm_runtime_use_autosuspend(dev);
76+
pm_runtime_mark_last_busy(dev);
77+
pm_runtime_set_active(dev);
78+
pm_runtime_enable(dev);
79+
80+
return 0;
81+
}
82+
83+
static void wcd_sdw_component_unbind(struct device *dev, struct device *master, void *data)
84+
{
85+
pm_runtime_disable(dev);
86+
pm_runtime_set_suspended(dev);
87+
pm_runtime_dont_use_autosuspend(dev);
88+
}
89+
90+
const struct component_ops wcd_sdw_component_ops = {
91+
.bind = wcd_sdw_component_bind,
92+
.unbind = wcd_sdw_component_unbind,
93+
};
94+
EXPORT_SYMBOL_GPL(wcd_sdw_component_ops);
95+
6996
MODULE_DESCRIPTION("Common Qualcomm WCD Codec helpers driver");
7097
MODULE_LICENSE("GPL");

sound/soc/codecs/wcd-common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct wcd_common {
3434
u32 micb_vout[WCD_MAX_MICBIAS];
3535
};
3636

37+
extern const struct component_ops wcd_sdw_component_ops;
3738
int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv);
3839
int wcd_dt_parse_micbias_info(struct wcd_common *common);
3940

sound/soc/codecs/wcd937x-sdw.c

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -983,31 +983,6 @@ static const struct sdw_slave_ops wcd9370_slave_ops = {
983983
.interrupt_callback = wcd9370_interrupt_callback,
984984
};
985985

986-
static int wcd937x_sdw_component_bind(struct device *dev,
987-
struct device *master, void *data)
988-
{
989-
pm_runtime_set_autosuspend_delay(dev, 3000);
990-
pm_runtime_use_autosuspend(dev);
991-
pm_runtime_mark_last_busy(dev);
992-
pm_runtime_set_active(dev);
993-
pm_runtime_enable(dev);
994-
995-
return 0;
996-
}
997-
998-
static void wcd937x_sdw_component_unbind(struct device *dev,
999-
struct device *master, void *data)
1000-
{
1001-
pm_runtime_disable(dev);
1002-
pm_runtime_set_suspended(dev);
1003-
pm_runtime_dont_use_autosuspend(dev);
1004-
}
1005-
1006-
static const struct component_ops wcd937x_sdw_component_ops = {
1007-
.bind = wcd937x_sdw_component_bind,
1008-
.unbind = wcd937x_sdw_component_unbind,
1009-
};
1010-
1011986
static int wcd9370_probe(struct sdw_slave *pdev,
1012987
const struct sdw_device_id *id)
1013988
{
@@ -1093,7 +1068,7 @@ static int wcd9370_probe(struct sdw_slave *pdev,
10931068
}
10941069

10951070

1096-
ret = component_add(dev, &wcd937x_sdw_component_ops);
1071+
ret = component_add(dev, &wcd_sdw_component_ops);
10971072
if (ret)
10981073
return ret;
10991074

@@ -1107,7 +1082,7 @@ static int wcd9370_remove(struct sdw_slave *pdev)
11071082
{
11081083
struct device *dev = &pdev->dev;
11091084

1110-
component_del(dev, &wcd937x_sdw_component_ops);
1085+
component_del(dev, &wcd_sdw_component_ops);
11111086

11121087
return 0;
11131088
}

sound/soc/codecs/wcd938x-sdw.c

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,22 +1182,6 @@ static const struct sdw_slave_ops wcd9380_slave_ops = {
11821182
.bus_config = wcd9380_bus_config,
11831183
};
11841184

1185-
static int wcd938x_sdw_component_bind(struct device *dev,
1186-
struct device *master, void *data)
1187-
{
1188-
return 0;
1189-
}
1190-
1191-
static void wcd938x_sdw_component_unbind(struct device *dev,
1192-
struct device *master, void *data)
1193-
{
1194-
}
1195-
1196-
static const struct component_ops wcd938x_sdw_component_ops = {
1197-
.bind = wcd938x_sdw_component_bind,
1198-
.unbind = wcd938x_sdw_component_unbind,
1199-
};
1200-
12011185
static int wcd9380_probe(struct sdw_slave *pdev,
12021186
const struct sdw_device_id *id)
12031187
{
@@ -1262,7 +1246,7 @@ static int wcd9380_probe(struct sdw_slave *pdev,
12621246
pm_runtime_set_active(dev);
12631247
pm_runtime_enable(dev);
12641248

1265-
ret = component_add(dev, &wcd938x_sdw_component_ops);
1249+
ret = component_add(dev, &wcd_sdw_component_ops);
12661250
if (ret)
12671251
goto err_disable_rpm;
12681252

@@ -1280,7 +1264,7 @@ static int wcd9380_remove(struct sdw_slave *pdev)
12801264
{
12811265
struct device *dev = &pdev->dev;
12821266

1283-
component_del(dev, &wcd938x_sdw_component_ops);
1267+
component_del(dev, &wcd_sdw_component_ops);
12841268

12851269
pm_runtime_disable(dev);
12861270
pm_runtime_set_suspended(dev);

sound/soc/codecs/wcd939x-sdw.c

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,31 +1378,6 @@ static const struct sdw_slave_ops wcd9390_slave_ops = {
13781378
.bus_config = wcd9390_bus_config,
13791379
};
13801380

1381-
static int wcd939x_sdw_component_bind(struct device *dev, struct device *master,
1382-
void *data)
1383-
{
1384-
pm_runtime_set_autosuspend_delay(dev, 3000);
1385-
pm_runtime_use_autosuspend(dev);
1386-
pm_runtime_mark_last_busy(dev);
1387-
pm_runtime_set_active(dev);
1388-
pm_runtime_enable(dev);
1389-
1390-
return 0;
1391-
}
1392-
1393-
static void wcd939x_sdw_component_unbind(struct device *dev,
1394-
struct device *master, void *data)
1395-
{
1396-
pm_runtime_disable(dev);
1397-
pm_runtime_set_suspended(dev);
1398-
pm_runtime_dont_use_autosuspend(dev);
1399-
}
1400-
1401-
static const struct component_ops wcd939x_sdw_component_ops = {
1402-
.bind = wcd939x_sdw_component_bind,
1403-
.unbind = wcd939x_sdw_component_unbind,
1404-
};
1405-
14061381
static int wcd9390_probe(struct sdw_slave *pdev, const struct sdw_device_id *id)
14071382
{
14081383
struct device *dev = &pdev->dev;
@@ -1466,7 +1441,7 @@ static int wcd9390_probe(struct sdw_slave *pdev, const struct sdw_device_id *id)
14661441
regcache_cache_only(wcd->regmap, true);
14671442
}
14681443

1469-
ret = component_add(dev, &wcd939x_sdw_component_ops);
1444+
ret = component_add(dev, &wcd_sdw_component_ops);
14701445
if (ret)
14711446
return ret;
14721447

@@ -1481,7 +1456,7 @@ static int wcd9390_remove(struct sdw_slave *pdev)
14811456
struct device *dev = &pdev->dev;
14821457
struct wcd939x_sdw_priv *wcd = dev_get_drvdata(dev);
14831458

1484-
component_del(dev, &wcd939x_sdw_component_ops);
1459+
component_del(dev, &wcd_sdw_component_ops);
14851460

14861461
if (wcd->regmap)
14871462
regmap_exit(wcd->regmap);

0 commit comments

Comments
 (0)