Skip to content

Commit cab82ca

Browse files
rfvirgilbroonie
authored andcommitted
ASoC: cs35l56: Share common SoundWire interrupt enable/disable code
Move the duplicated SoundWire interrupt enable/disable code into shared functions. These new functions are in cs35l56.c to prevent circular dependency between cs35l56.c and cs35l56-sdw.c Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Link: https://patch.msgid.link/20260529140350.408557-1-rf@opensource.cirrus.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 3ef902c commit cab82ca

3 files changed

Lines changed: 58 additions & 49 deletions

File tree

sound/soc/codecs/cs35l56-sdw.c

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,8 @@ static void cs35l56_sdw_init(struct sdw_slave *peripheral)
230230
* cs35l56_init can return with !init_done if it triggered
231231
* a soft reset.
232232
*/
233-
if (cs35l56->base.init_done) {
234-
/* Enable SoundWire interrupts */
235-
sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_MASK_1,
236-
CS35L56_SDW_INT_MASK_CODEC_IRQ);
237-
}
233+
if (cs35l56->base.init_done)
234+
cs35l56_unmask_soundwire_interrupts(cs35l56->sdw_peripheral);
238235

239236
out:
240237
pm_runtime_put_autosuspend(cs35l56->base.dev);
@@ -259,15 +256,11 @@ static int cs35l56_sdw_interrupt(struct sdw_slave *peripheral,
259256
pm_runtime_get_noresume(cs35l56->base.dev);
260257

261258
/*
262-
* Mask and clear until it has been handled. The read of GEN_INT_STAT_1
263-
* is required as per the SoundWire spec for interrupt status bits
264-
* to clear. GEN_INT_MASK_1 masks the _inputs_ to GEN_INT_STAT1.
259+
* Mask and clear until it has been handled.
265260
* None of the interrupts are time-critical so use the
266261
* power-efficient queue.
267262
*/
268-
sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
269-
sdw_read_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1);
270-
sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
263+
cs35l56_mask_soundwire_interrupts(peripheral);
271264
queue_work(system_power_efficient_wq, &cs35l56->sdw_irq_work);
272265

273266
return 0;
@@ -283,8 +276,7 @@ static void cs35l56_sdw_irq_work(struct work_struct *work)
283276

284277
/* unmask interrupts */
285278
if (!cs35l56->sdw_irq_no_unmask)
286-
sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1,
287-
CS35L56_SDW_INT_MASK_CODEC_IRQ);
279+
cs35l56_unmask_soundwire_interrupts(cs35l56->sdw_peripheral);
288280

289281
pm_runtime_put_autosuspend(cs35l56->base.dev);
290282
}
@@ -441,9 +433,7 @@ static int __maybe_unused cs35l56_sdw_runtime_resume(struct device *dev)
441433
if (ret)
442434
return ret;
443435

444-
/* Re-enable SoundWire interrupts */
445-
sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1,
446-
CS35L56_SDW_INT_MASK_CODEC_IRQ);
436+
cs35l56_unmask_soundwire_interrupts(cs35l56->sdw_peripheral);
447437

448438
return 0;
449439
}
@@ -455,18 +445,7 @@ static int __maybe_unused cs35l56_sdw_system_suspend(struct device *dev)
455445
if (!cs35l56->base.init_done)
456446
return 0;
457447

458-
/*
459-
* Disable SoundWire interrupts.
460-
* Flush - don't cancel because that could leave an unbalanced pm_runtime_get.
461-
*/
462-
cs35l56->sdw_irq_no_unmask = true;
463-
flush_work(&cs35l56->sdw_irq_work);
464-
465-
/* Mask interrupts and flush in case sdw_irq_work was queued again */
466-
sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
467-
sdw_read_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1);
468-
sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
469-
flush_work(&cs35l56->sdw_irq_work);
448+
cs35l56_disable_sdw_interrupts(cs35l56);
470449

471450
return cs35l56_system_suspend(dev);
472451
}
@@ -542,13 +521,7 @@ static void cs35l56_sdw_remove(struct sdw_slave *peripheral)
542521
{
543522
struct cs35l56_private *cs35l56 = dev_get_drvdata(&peripheral->dev);
544523

545-
/* Disable SoundWire interrupts */
546-
cs35l56->sdw_irq_no_unmask = true;
547-
flush_work(&cs35l56->sdw_irq_work);
548-
sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
549-
sdw_read_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1);
550-
sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
551-
flush_work(&cs35l56->sdw_irq_work);
524+
cs35l56_disable_sdw_interrupts(cs35l56);
552525

553526
cs35l56_remove(cs35l56);
554527
}

sound/soc/codecs/cs35l56.c

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,49 @@
3737
#include "wm_adsp.h"
3838
#include "cs35l56.h"
3939

40+
void cs35l56_mask_soundwire_interrupts(struct sdw_slave *peripheral)
41+
{
42+
/*
43+
* The read of GEN_INT_STAT_1 is required as per the SoundWire spec
44+
* for interrupt status bits to clear.
45+
* GEN_INT_MASK_1 masks the _inputs_ to GEN_INT_STAT1.
46+
*/
47+
sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
48+
sdw_read_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1);
49+
sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
50+
}
51+
EXPORT_SYMBOL_NS_GPL(cs35l56_mask_soundwire_interrupts, "SND_SOC_CS35L56_CORE");
52+
53+
void cs35l56_unmask_soundwire_interrupts(struct sdw_slave *peripheral)
54+
{
55+
sdw_write_no_pm(peripheral, CS35L56_SDW_GEN_INT_MASK_1, CS35L56_SDW_INT_MASK_CODEC_IRQ);
56+
}
57+
EXPORT_SYMBOL_NS_GPL(cs35l56_unmask_soundwire_interrupts, "SND_SOC_CS35L56_CORE");
58+
59+
void cs35l56_disable_sdw_interrupts(struct cs35l56_private *cs35l56)
60+
{
61+
if (!cs35l56->sdw_peripheral)
62+
return;
63+
64+
cs35l56->sdw_irq_no_unmask = true;
65+
flush_work(&cs35l56->sdw_irq_work);
66+
67+
/* Mask interrupts and flush in case sdw_irq_work was queued again */
68+
cs35l56_mask_soundwire_interrupts(cs35l56->sdw_peripheral);
69+
flush_work(&cs35l56->sdw_irq_work);
70+
}
71+
EXPORT_SYMBOL_NS_GPL(cs35l56_disable_sdw_interrupts, "SND_SOC_CS35L56_CORE");
72+
73+
void cs35l56_enable_sdw_interrupts(struct cs35l56_private *cs35l56)
74+
{
75+
if (!cs35l56->sdw_peripheral)
76+
return;
77+
78+
cs35l56->sdw_irq_no_unmask = false;
79+
cs35l56_unmask_soundwire_interrupts(cs35l56->sdw_peripheral);
80+
}
81+
EXPORT_SYMBOL_NS_GPL(cs35l56_enable_sdw_interrupts, "SND_SOC_CS35L56_CORE");
82+
4083
static int cs35l56_dsp_event(struct snd_soc_dapm_widget *w,
4184
struct snd_kcontrol *kcontrol, int event);
4285

@@ -790,14 +833,7 @@ static void cs35l56_patch(struct cs35l56_private *cs35l56, bool firmware_missing
790833
* Setting sdw_irq_no_unmask prevents the handler re-enabling
791834
* the SoundWire interrupt.
792835
*/
793-
if (cs35l56->sdw_peripheral) {
794-
cs35l56->sdw_irq_no_unmask = true;
795-
flush_work(&cs35l56->sdw_irq_work);
796-
sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1, 0);
797-
sdw_read_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1);
798-
sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_STAT_1, 0xFF);
799-
flush_work(&cs35l56->sdw_irq_work);
800-
}
836+
cs35l56_disable_sdw_interrupts(cs35l56);
801837

802838
ret = cs35l56_firmware_shutdown(&cs35l56->base);
803839
if (ret)
@@ -849,12 +885,7 @@ static void cs35l56_patch(struct cs35l56_private *cs35l56, bool firmware_missing
849885
err_unlock:
850886
mutex_unlock(&cs35l56->base.irq_lock);
851887
err:
852-
/* Re-enable SoundWire interrupts */
853-
if (cs35l56->sdw_peripheral) {
854-
cs35l56->sdw_irq_no_unmask = false;
855-
sdw_write_no_pm(cs35l56->sdw_peripheral, CS35L56_SDW_GEN_INT_MASK_1,
856-
CS35L56_SDW_INT_MASK_CODEC_IRQ);
857-
}
888+
cs35l56_enable_sdw_interrupts(cs35l56);
858889
}
859890

860891
static void cs35l56_dsp_work(struct work_struct *work)

sound/soc/codecs/cs35l56.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ static inline struct cs35l56_private *cs35l56_private_from_base(struct cs35l56_b
6666

6767
extern const struct dev_pm_ops cs35l56_pm_ops_i2c_spi;
6868

69+
void cs35l56_mask_soundwire_interrupts(struct sdw_slave *peripheral);
70+
void cs35l56_unmask_soundwire_interrupts(struct sdw_slave *peripheral);
71+
void cs35l56_disable_sdw_interrupts(struct cs35l56_private *cs35l56);
72+
void cs35l56_enable_sdw_interrupts(struct cs35l56_private *cs35l56);
73+
6974
int cs35l56_system_suspend(struct device *dev);
7075
int cs35l56_system_suspend_late(struct device *dev);
7176
int cs35l56_system_suspend_no_irq(struct device *dev);

0 commit comments

Comments
 (0)