Skip to content

Commit 59aebbb

Browse files
Srinivas Kandagatlabroonie
authored andcommitted
ASoC: codecs: wcd-common: move status_update callback to common
Soundwire update_status, bus_config and interrupt callbacks for wcd937x, 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-12-srinivas.kandagatla@oss.qualcomm.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 45f2c5e commit 59aebbb

5 files changed

Lines changed: 62 additions & 100 deletions

File tree

sound/soc/codecs/wcd-common.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@
99
#include <linux/printk.h>
1010
#include <linux/component.h>
1111
#include <linux/pm_runtime.h>
12+
#include <linux/soundwire/sdw.h>
13+
#include <linux/soundwire/sdw_type.h>
14+
#include <linux/regmap.h>
1215

1316
#include "wcd-common.h"
1417

1518
#define WCD_MIN_MICBIAS_MV 1000
1619
#define WCD_DEF_MICBIAS_MV 1800
1720
#define WCD_MAX_MICBIAS_MV 2850
1821

22+
#define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m))
23+
1924
int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv)
2025
{
2126
/* min micbias voltage is 1V and maximum is 2.85V */
@@ -93,5 +98,46 @@ const struct component_ops wcd_sdw_component_ops = {
9398
};
9499
EXPORT_SYMBOL_GPL(wcd_sdw_component_ops);
95100

101+
int wcd_update_status(struct sdw_slave *slave, enum sdw_slave_status status)
102+
{
103+
struct regmap *regmap = dev_get_regmap(&slave->dev, NULL);
104+
105+
if (regmap && status == SDW_SLAVE_ATTACHED) {
106+
/* Write out any cached changes that happened between probe and attach */
107+
regcache_cache_only(regmap, false);
108+
return regcache_sync(regmap);
109+
}
110+
111+
return 0;
112+
}
113+
EXPORT_SYMBOL_GPL(wcd_update_status);
114+
115+
int wcd_bus_config(struct sdw_slave *slave, struct sdw_bus_params *params)
116+
{
117+
sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 0x01);
118+
119+
return 0;
120+
}
121+
EXPORT_SYMBOL_GPL(wcd_bus_config);
122+
123+
int wcd_interrupt_callback(struct sdw_slave *slave, struct irq_domain *slave_irq,
124+
unsigned int wcd_intr_status0, unsigned int wcd_intr_status1,
125+
unsigned int wcd_intr_status2)
126+
{
127+
struct regmap *regmap = dev_get_regmap(&slave->dev, NULL);
128+
u32 sts1, sts2, sts3;
129+
130+
do {
131+
handle_nested_irq(irq_find_mapping(slave_irq, 0));
132+
regmap_read(regmap, wcd_intr_status0, &sts1);
133+
regmap_read(regmap, wcd_intr_status1, &sts2);
134+
regmap_read(regmap, wcd_intr_status2, &sts3);
135+
136+
} while (sts1 || sts2 || sts3);
137+
138+
return IRQ_HANDLED;
139+
}
140+
EXPORT_SYMBOL_GPL(wcd_interrupt_callback);
141+
96142
MODULE_DESCRIPTION("Common Qualcomm WCD Codec helpers driver");
97143
MODULE_LICENSE("GPL");

sound/soc/codecs/wcd-common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,10 @@ struct wcd_common {
3737
extern const struct component_ops wcd_sdw_component_ops;
3838
int wcd_get_micb_vout_ctl_val(struct device *dev, u32 micb_mv);
3939
int wcd_dt_parse_micbias_info(struct wcd_common *common);
40+
int wcd_update_status(struct sdw_slave *slave, enum sdw_slave_status status);
41+
int wcd_bus_config(struct sdw_slave *slave, struct sdw_bus_params *params);
42+
int wcd_interrupt_callback(struct sdw_slave *slave, struct irq_domain *slave_irq,
43+
unsigned int wcd_intr_status0, unsigned int wcd_intr_status1,
44+
unsigned int wcd_intr_status2);
4045

4146
#endif /* __WCD_COMMON_H__ */

sound/soc/codecs/wcd937x-sdw.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,6 @@ int wcd937x_sdw_hw_params(struct wcd937x_sdw_priv *wcd,
112112
}
113113
EXPORT_SYMBOL_GPL(wcd937x_sdw_hw_params);
114114

115-
static int wcd9370_update_status(struct sdw_slave *slave, enum sdw_slave_status status)
116-
{
117-
struct wcd937x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
118-
119-
if (wcd->regmap && status == SDW_SLAVE_ATTACHED) {
120-
/* Write out any cached changes that happened between probe and attach */
121-
regcache_cache_only(wcd->regmap, false);
122-
return regcache_sync(wcd->regmap);
123-
}
124-
125-
return 0;
126-
}
127-
128115
/*
129116
* Handle Soundwire out-of-band interrupt event by triggering
130117
* the first irq of the slave_irq irq domain, which then will
@@ -135,18 +122,9 @@ static int wcd9370_interrupt_callback(struct sdw_slave *slave,
135122
struct sdw_slave_intr_status *status)
136123
{
137124
struct wcd937x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
138-
struct irq_domain *slave_irq = wcd->slave_irq;
139-
u32 sts1, sts2, sts3;
140-
141-
do {
142-
handle_nested_irq(irq_find_mapping(slave_irq, 0));
143-
regmap_read(wcd->regmap, WCD937X_DIGITAL_INTR_STATUS_0, &sts1);
144-
regmap_read(wcd->regmap, WCD937X_DIGITAL_INTR_STATUS_1, &sts2);
145-
regmap_read(wcd->regmap, WCD937X_DIGITAL_INTR_STATUS_2, &sts3);
146-
147-
} while (sts1 || sts2 || sts3);
148125

149-
return IRQ_HANDLED;
126+
return wcd_interrupt_callback(slave, wcd->slave_irq, WCD937X_DIGITAL_INTR_STATUS_0,
127+
WCD937X_DIGITAL_INTR_STATUS_1, WCD937X_DIGITAL_INTR_STATUS_2);
150128
}
151129

152130
static const struct reg_default wcd937x_defaults[] = {
@@ -979,7 +957,7 @@ static const struct regmap_config wcd937x_regmap_config = {
979957
};
980958

981959
static const struct sdw_slave_ops wcd9370_slave_ops = {
982-
.update_status = wcd9370_update_status,
960+
.update_status = wcd_update_status,
983961
.interrupt_callback = wcd9370_interrupt_callback,
984962
};
985963

sound/soc/codecs/wcd938x-sdw.c

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include "wcd938x.h"
2121
#include "wcd-common.h"
2222

23-
#define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m))
24-
2523
static const struct wcd_sdw_ch_info wcd938x_sdw_rx_ch_info[] = {
2624
WCD_SDW_CH(WCD938X_HPH_L, WCD938X_HPH_PORT, BIT(0)),
2725
WCD_SDW_CH(WCD938X_HPH_R, WCD938X_HPH_PORT, BIT(1)),
@@ -142,44 +140,13 @@ int wcd938x_sdw_set_sdw_stream(struct wcd938x_sdw_priv *wcd,
142140
}
143141
EXPORT_SYMBOL_GPL(wcd938x_sdw_set_sdw_stream);
144142

145-
static int wcd9380_update_status(struct sdw_slave *slave,
146-
enum sdw_slave_status status)
147-
{
148-
struct wcd938x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
149-
150-
if (wcd->regmap && (status == SDW_SLAVE_ATTACHED)) {
151-
/* Write out any cached changes that happened between probe and attach */
152-
regcache_cache_only(wcd->regmap, false);
153-
return regcache_sync(wcd->regmap);
154-
}
155-
156-
return 0;
157-
}
158-
159-
static int wcd9380_bus_config(struct sdw_slave *slave,
160-
struct sdw_bus_params *params)
161-
{
162-
sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank), 0x01);
163-
164-
return 0;
165-
}
166-
167143
static int wcd9380_interrupt_callback(struct sdw_slave *slave,
168144
struct sdw_slave_intr_status *status)
169145
{
170146
struct wcd938x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
171-
struct irq_domain *slave_irq = wcd->slave_irq;
172-
u32 sts1, sts2, sts3;
173-
174-
do {
175-
handle_nested_irq(irq_find_mapping(slave_irq, 0));
176-
regmap_read(wcd->regmap, WCD938X_DIGITAL_INTR_STATUS_0, &sts1);
177-
regmap_read(wcd->regmap, WCD938X_DIGITAL_INTR_STATUS_1, &sts2);
178-
regmap_read(wcd->regmap, WCD938X_DIGITAL_INTR_STATUS_2, &sts3);
179-
180-
} while (sts1 || sts2 || sts3);
181147

182-
return IRQ_HANDLED;
148+
return wcd_interrupt_callback(slave, wcd->slave_irq, WCD938X_DIGITAL_INTR_STATUS_0,
149+
WCD938X_DIGITAL_INTR_STATUS_1, WCD938X_DIGITAL_INTR_STATUS_2);
183150
}
184151

185152
static const struct reg_default wcd938x_defaults[] = {
@@ -1177,9 +1144,9 @@ static const struct regmap_config wcd938x_regmap_config = {
11771144
};
11781145

11791146
static const struct sdw_slave_ops wcd9380_slave_ops = {
1180-
.update_status = wcd9380_update_status,
1147+
.update_status = wcd_update_status,
11811148
.interrupt_callback = wcd9380_interrupt_callback,
1182-
.bus_config = wcd9380_bus_config,
1149+
.bus_config = wcd_bus_config,
11831150
};
11841151

11851152
static int wcd9380_probe(struct sdw_slave *pdev,

sound/soc/codecs/wcd939x-sdw.c

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include "wcd939x.h"
2323
#include "wcd-common.h"
2424

25-
#define SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(m) (0xE0 + 0x10 * (m))
26-
2725
static const struct wcd_sdw_ch_info wcd939x_sdw_rx_ch_info[] = {
2826
WCD_SDW_CH(WCD939X_HPH_L, WCD939X_HPH_PORT, BIT(0)),
2927
WCD_SDW_CH(WCD939X_HPH_R, WCD939X_HPH_PORT, BIT(1)),
@@ -187,29 +185,6 @@ int wcd939x_sdw_set_sdw_stream(struct wcd939x_sdw_priv *wcd,
187185
}
188186
EXPORT_SYMBOL_GPL(wcd939x_sdw_set_sdw_stream);
189187

190-
static int wcd9390_update_status(struct sdw_slave *slave,
191-
enum sdw_slave_status status)
192-
{
193-
struct wcd939x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
194-
195-
if (wcd->regmap && status == SDW_SLAVE_ATTACHED) {
196-
/* Write out any cached changes that happened between probe and attach */
197-
regcache_cache_only(wcd->regmap, false);
198-
return regcache_sync(wcd->regmap);
199-
}
200-
201-
return 0;
202-
}
203-
204-
static int wcd9390_bus_config(struct sdw_slave *slave,
205-
struct sdw_bus_params *params)
206-
{
207-
sdw_write(slave, SWRS_SCP_HOST_CLK_DIV2_CTL_BANK(params->next_bank),
208-
0x01);
209-
210-
return 0;
211-
}
212-
213188
/*
214189
* Handle Soundwire out-of-band interrupt event by triggering
215190
* the first irq of the slave_irq irq domain, which then will
@@ -220,18 +195,9 @@ static int wcd9390_interrupt_callback(struct sdw_slave *slave,
220195
struct sdw_slave_intr_status *status)
221196
{
222197
struct wcd939x_sdw_priv *wcd = dev_get_drvdata(&slave->dev);
223-
struct irq_domain *slave_irq = wcd->slave_irq;
224-
u32 sts1, sts2, sts3;
225-
226-
do {
227-
handle_nested_irq(irq_find_mapping(slave_irq, 0));
228-
regmap_read(wcd->regmap, WCD939X_DIGITAL_INTR_STATUS_0, &sts1);
229-
regmap_read(wcd->regmap, WCD939X_DIGITAL_INTR_STATUS_1, &sts2);
230-
regmap_read(wcd->regmap, WCD939X_DIGITAL_INTR_STATUS_2, &sts3);
231-
232-
} while (sts1 || sts2 || sts3);
233198

234-
return IRQ_HANDLED;
199+
return wcd_interrupt_callback(slave, wcd->slave_irq, WCD939X_DIGITAL_INTR_STATUS_0,
200+
WCD939X_DIGITAL_INTR_STATUS_1, WCD939X_DIGITAL_INTR_STATUS_2);
235201
}
236202

237203
static const struct reg_default wcd939x_defaults[] = {
@@ -1364,9 +1330,9 @@ static const struct regmap_config wcd939x_regmap_config = {
13641330
};
13651331

13661332
static const struct sdw_slave_ops wcd9390_slave_ops = {
1367-
.update_status = wcd9390_update_status,
1333+
.update_status = wcd_update_status,
13681334
.interrupt_callback = wcd9390_interrupt_callback,
1369-
.bus_config = wcd9390_bus_config,
1335+
.bus_config = wcd_bus_config,
13701336
};
13711337

13721338
static int wcd9390_probe(struct sdw_slave *pdev, const struct sdw_device_id *id)

0 commit comments

Comments
 (0)