Define common inline function for register update.
Use this inline function for updating SoundWire Pad registers
and enable/disable SoundWire interrupt control registers.
Signed-off-by: Vijendar Mukunda <[email protected]>
---
drivers/soundwire/amd_init.c | 36 +++++++++++++++------------------
drivers/soundwire/amd_init.h | 8 ++++++++
drivers/soundwire/amd_manager.c | 13 ++++++------
3 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/drivers/soundwire/amd_init.c b/drivers/soundwire/amd_init.c
index e45dc8261ab1..4cd26f3a21f5 100644
--- a/drivers/soundwire/amd_init.c
+++ b/drivers/soundwire/amd_init.c
@@ -17,42 +17,38 @@
#define ACP_PAD_PULLDOWN_CTRL 0x0001448
#define ACP_SW_PAD_KEEPER_EN 0x0001454
-#define AMD_SDW_PAD_PULLDOWN_CTRL_ENABLE_MASK 0x7f9a
-#define AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK 0x7f9f
-#define AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK 0x7ffa
-#define AMD_SDW0_PAD_EN_MASK 1
-#define AMD_SDW1_PAD_EN_MASK 0x10
-#define AMD_SDW_PAD_EN_MASK (AMD_SDW0_PAD_EN_MASK | AMD_SDW1_PAD_EN_MASK)
+#define AMD_SDW0_PAD_CTRL_MASK 0x60
+#define AMD_SDW1_PAD_CTRL_MASK 5
+#define AMD_SDW_PAD_CTRL_MASK (AMD_SDW0_PAD_CTRL_MASK | AMD_SDW1_PAD_CTRL_MASK)
+#define AMD_SDW0_PAD_EN 1
+#define AMD_SDW1_PAD_EN 0x10
+#define AMD_SDW_PAD_EN (AMD_SDW0_PAD_EN | AMD_SDW1_PAD_EN)
static int amd_enable_sdw_pads(void __iomem *mmio, u32 link_mask, struct device *dev)
{
- u32 val;
- u32 pad_keeper_en_mask, pad_pulldown_ctrl_mask;
+ u32 pad_keeper_en, pad_pulldown_ctrl_mask;
switch (link_mask) {
case 1:
- pad_keeper_en_mask = AMD_SDW0_PAD_EN_MASK;
- pad_pulldown_ctrl_mask = AMD_SDW0_PAD_PULLDOWN_CTRL_ENABLE_MASK;
+ pad_keeper_en = AMD_SDW0_PAD_EN;
+ pad_pulldown_ctrl_mask = AMD_SDW0_PAD_CTRL_MASK;
break;
case 2:
- pad_keeper_en_mask = AMD_SDW1_PAD_EN_MASK;
- pad_pulldown_ctrl_mask = AMD_SDW1_PAD_PULLDOWN_CTRL_ENABLE_MASK;
+ pad_keeper_en = AMD_SDW1_PAD_EN;
+ pad_pulldown_ctrl_mask = AMD_SDW1_PAD_CTRL_MASK;
break;
case 3:
- pad_keeper_en_mask = AMD_SDW_PAD_EN_MASK;
- pad_pulldown_ctrl_mask = AMD_SDW_PAD_PULLDOWN_CTRL_ENABLE_MASK;
+ pad_keeper_en = AMD_SDW_PAD_EN;
+ pad_pulldown_ctrl_mask = AMD_SDW_PAD_CTRL_MASK;
break;
default:
dev_err(dev, "No SDW Links are enabled\n");
return -ENODEV;
}
- val = readl(mmio + ACP_SW_PAD_KEEPER_EN);
- val |= pad_keeper_en_mask;
- writel(val, mmio + ACP_SW_PAD_KEEPER_EN);
- val = readl(mmio + ACP_PAD_PULLDOWN_CTRL);
- val &= pad_pulldown_ctrl_mask;
- writel(val, mmio + ACP_PAD_PULLDOWN_CTRL);
+ amd_updatel(mmio, ACP_SW_PAD_KEEPER_EN, pad_keeper_en, pad_keeper_en);
+ amd_updatel(mmio, ACP_PAD_PULLDOWN_CTRL, pad_pulldown_ctrl_mask, 0);
+
return 0;
}
diff --git a/drivers/soundwire/amd_init.h b/drivers/soundwire/amd_init.h
index 928b0c707162..5e7b43836a37 100644
--- a/drivers/soundwire/amd_init.h
+++ b/drivers/soundwire/amd_init.h
@@ -10,4 +10,12 @@
int amd_sdw_manager_start(struct amd_sdw_manager *amd_manager);
+static inline void amd_updatel(void __iomem *mmio, int offset, u32 mask, u32 val)
+{
+ u32 tmp;
+
+ tmp = readl(mmio + offset);
+ tmp = (tmp & ~mask) | val;
+ writel(tmp, mmio + offset);
+}
#endif
diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
index 7cd24bd8e224..1066d87aa011 100644
--- a/drivers/soundwire/amd_manager.c
+++ b/drivers/soundwire/amd_manager.c
@@ -89,9 +89,8 @@ static void amd_enable_sdw_interrupts(struct amd_sdw_manager *amd_manager)
u32 val;
mutex_lock(amd_manager->acp_sdw_lock);
- val = readl(amd_manager->acp_mmio + ACP_EXTERNAL_INTR_CNTL(amd_manager->instance));
- val |= sdw_manager_reg_mask_array[amd_manager->instance];
- writel(val, amd_manager->acp_mmio + ACP_EXTERNAL_INTR_CNTL(amd_manager->instance));
+ val = sdw_manager_reg_mask_array[amd_manager->instance];
+ amd_updatel(amd_manager->acp_mmio, ACP_EXTERNAL_INTR_CNTL(amd_manager->instance), val, val);
mutex_unlock(amd_manager->acp_sdw_lock);
writel(AMD_SDW_IRQ_MASK_0TO7, amd_manager->mmio +
@@ -103,12 +102,12 @@ static void amd_enable_sdw_interrupts(struct amd_sdw_manager *amd_manager)
static void amd_disable_sdw_interrupts(struct amd_sdw_manager *amd_manager)
{
- u32 val;
+ u32 irq_mask;
mutex_lock(amd_manager->acp_sdw_lock);
- val = readl(amd_manager->acp_mmio + ACP_EXTERNAL_INTR_CNTL(amd_manager->instance));
- val &= ~sdw_manager_reg_mask_array[amd_manager->instance];
- writel(val, amd_manager->acp_mmio + ACP_EXTERNAL_INTR_CNTL(amd_manager->instance));
+ irq_mask = sdw_manager_reg_mask_array[amd_manager->instance];
+ amd_updatel(amd_manager->acp_mmio, ACP_EXTERNAL_INTR_CNTL(amd_manager->instance),
+ irq_mask, 0);
mutex_unlock(amd_manager->acp_sdw_lock);
writel(0x00, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_0TO7);
--
2.34.1
When SoundWire Wake interrupt is enabled along with SoundWire Wake
enable register, SoundWire wake interrupt will be reported
when SoundWire manager is in D3 state and ACP is in D3 state.
When SoundWire Wake interrupt is reported, it will invoke runtime
resume of the SoundWire manager device.
In case of system level suspend, for ClockStop Mode SoundWire Wake
interrupt should be disabled.
It should be enabled only for runtime suspend scenario.
Change wake interrupt enable/disable sequence for ClockStop Mode in
system level suspend and runtime suspend sceanrio.
Fixes: 9cf1efc5ed2d ("soundwire: amd: add pm_prepare callback and pm ops support")
Signed-off-by: Vijendar Mukunda <[email protected]>
---
drivers/soundwire/amd_manager.c | 15 +++++++++++++++
drivers/soundwire/amd_manager.h | 3 ++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
index 1066d87aa011..20d94bcfc9b4 100644
--- a/drivers/soundwire/amd_manager.c
+++ b/drivers/soundwire/amd_manager.c
@@ -129,6 +129,19 @@ static void amd_sdw_set_frameshape(struct amd_sdw_manager *amd_manager)
writel(frame_size, amd_manager->mmio + ACP_SW_FRAMESIZE);
}
+static void amd_sdw_wake_enable(struct amd_sdw_manager *amd_manager, bool enable)
+{
+ u32 wake_ctrl;
+
+ wake_ctrl = readl(amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11);
+ if (enable)
+ wake_ctrl |= AMD_SDW_WAKE_INTR_MASK;
+ else
+ wake_ctrl &= ~AMD_SDW_WAKE_INTR_MASK;
+
+ writel(wake_ctrl, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11);
+}
+
static void amd_sdw_ctl_word_prep(u32 *lower_word, u32 *upper_word, struct sdw_msg *msg,
int cmd_offset)
{
@@ -1094,6 +1107,7 @@ static int __maybe_unused amd_suspend(struct device *dev)
}
if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
+ amd_sdw_wake_enable(amd_manager, false);
return amd_sdw_clock_stop(amd_manager);
} else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) {
/*
@@ -1120,6 +1134,7 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)
return 0;
}
if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
+ amd_sdw_wake_enable(amd_manager, true);
return amd_sdw_clock_stop(amd_manager);
} else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) {
ret = amd_sdw_clock_stop(amd_manager);
diff --git a/drivers/soundwire/amd_manager.h b/drivers/soundwire/amd_manager.h
index 418b679e0b1a..707065468e05 100644
--- a/drivers/soundwire/amd_manager.h
+++ b/drivers/soundwire/amd_manager.h
@@ -152,7 +152,7 @@
#define AMD_SDW0_EXT_INTR_MASK 0x200000
#define AMD_SDW1_EXT_INTR_MASK 4
#define AMD_SDW_IRQ_MASK_0TO7 0x77777777
-#define AMD_SDW_IRQ_MASK_8TO11 0x000d7777
+#define AMD_SDW_IRQ_MASK_8TO11 0x000c7777
#define AMD_SDW_IRQ_ERROR_MASK 0xff
#define AMD_SDW_MAX_FREQ_NUM 1
#define AMD_SDW0_MAX_TX_PORTS 3
@@ -190,6 +190,7 @@
#define AMD_SDW_CLK_RESUME_REQ 2
#define AMD_SDW_CLK_RESUME_DONE 3
#define AMD_SDW_WAKE_STAT_MASK BIT(16)
+#define AMD_SDW_WAKE_INTR_MASK BIT(16)
static u32 amd_sdw_freq_tbl[AMD_SDW_MAX_FREQ_NUM] = {
AMD_SDW_DEFAULT_CLK_FREQ,
--
2.34.1
On 27-03-24, 12:01, Vijendar Mukunda wrote:
> When SoundWire Wake interrupt is enabled along with SoundWire Wake
> enable register, SoundWire wake interrupt will be reported
> when SoundWire manager is in D3 state and ACP is in D3 state.
>
> When SoundWire Wake interrupt is reported, it will invoke runtime
> resume of the SoundWire manager device.
>
> In case of system level suspend, for ClockStop Mode SoundWire Wake
> interrupt should be disabled.
> It should be enabled only for runtime suspend scenario.
> Change wake interrupt enable/disable sequence for ClockStop Mode in
> system level suspend and runtime suspend sceanrio.
>
> Fixes: 9cf1efc5ed2d ("soundwire: amd: add pm_prepare callback and pm ops support")
>
no empty line b/w fixes and s-o-b line please
I have fixed it up while applying
Also, fixes should be first patch followed by other changes...
> Signed-off-by: Vijendar Mukunda <[email protected]>
> ---
> drivers/soundwire/amd_manager.c | 15 +++++++++++++++
> drivers/soundwire/amd_manager.h | 3 ++-
> 2 files changed, 17 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c
> index 1066d87aa011..20d94bcfc9b4 100644
> --- a/drivers/soundwire/amd_manager.c
> +++ b/drivers/soundwire/amd_manager.c
> @@ -129,6 +129,19 @@ static void amd_sdw_set_frameshape(struct amd_sdw_manager *amd_manager)
> writel(frame_size, amd_manager->mmio + ACP_SW_FRAMESIZE);
> }
>
> +static void amd_sdw_wake_enable(struct amd_sdw_manager *amd_manager, bool enable)
> +{
> + u32 wake_ctrl;
> +
> + wake_ctrl = readl(amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11);
> + if (enable)
> + wake_ctrl |= AMD_SDW_WAKE_INTR_MASK;
> + else
> + wake_ctrl &= ~AMD_SDW_WAKE_INTR_MASK;
> +
> + writel(wake_ctrl, amd_manager->mmio + ACP_SW_STATE_CHANGE_STATUS_MASK_8TO11);
> +}
> +
> static void amd_sdw_ctl_word_prep(u32 *lower_word, u32 *upper_word, struct sdw_msg *msg,
> int cmd_offset)
> {
> @@ -1094,6 +1107,7 @@ static int __maybe_unused amd_suspend(struct device *dev)
> }
>
> if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
> + amd_sdw_wake_enable(amd_manager, false);
> return amd_sdw_clock_stop(amd_manager);
> } else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) {
> /*
> @@ -1120,6 +1134,7 @@ static int __maybe_unused amd_suspend_runtime(struct device *dev)
> return 0;
> }
> if (amd_manager->power_mode_mask & AMD_SDW_CLK_STOP_MODE) {
> + amd_sdw_wake_enable(amd_manager, true);
> return amd_sdw_clock_stop(amd_manager);
> } else if (amd_manager->power_mode_mask & AMD_SDW_POWER_OFF_MODE) {
> ret = amd_sdw_clock_stop(amd_manager);
> diff --git a/drivers/soundwire/amd_manager.h b/drivers/soundwire/amd_manager.h
> index 418b679e0b1a..707065468e05 100644
> --- a/drivers/soundwire/amd_manager.h
> +++ b/drivers/soundwire/amd_manager.h
> @@ -152,7 +152,7 @@
> #define AMD_SDW0_EXT_INTR_MASK 0x200000
> #define AMD_SDW1_EXT_INTR_MASK 4
> #define AMD_SDW_IRQ_MASK_0TO7 0x77777777
> -#define AMD_SDW_IRQ_MASK_8TO11 0x000d7777
> +#define AMD_SDW_IRQ_MASK_8TO11 0x000c7777
> #define AMD_SDW_IRQ_ERROR_MASK 0xff
> #define AMD_SDW_MAX_FREQ_NUM 1
> #define AMD_SDW0_MAX_TX_PORTS 3
> @@ -190,6 +190,7 @@
> #define AMD_SDW_CLK_RESUME_REQ 2
> #define AMD_SDW_CLK_RESUME_DONE 3
> #define AMD_SDW_WAKE_STAT_MASK BIT(16)
> +#define AMD_SDW_WAKE_INTR_MASK BIT(16)
>
> static u32 amd_sdw_freq_tbl[AMD_SDW_MAX_FREQ_NUM] = {
> AMD_SDW_DEFAULT_CLK_FREQ,
> --
> 2.34.1
--
~Vinod
On Wed, 27 Mar 2024 12:01:42 +0530, Vijendar Mukunda wrote:
> Define common inline function for register update.
> Use this inline function for updating SoundWire Pad registers
> and enable/disable SoundWire interrupt control registers.
>
>
Applied, thanks!
[2/2] soundwire: amd: fix for wake interrupt handling for clockstop mode
commit: 63dc588e7af1392576071a1841298198c9cddee3
Best regards,
--
~Vinod