]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
ASoC: cs35l41: Refactor error release code
authorLucas Tanure <lucas.tanure@collabora.com>
Thu, 23 Feb 2023 08:43:22 +0000 (08:43 +0000)
committerMark Brown <broonie@kernel.org>
Sun, 5 Mar 2023 23:36:42 +0000 (23:36 +0000)
Add cs35l41_error_release function to handle error release sequences.

Signed-off-by: Lucas Tanure <lucas.tanure@collabora.com>
Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Reviewed-by: David Rhodes <david.rhodes@cirrus.com>
Link: https://lore.kernel.org/r/20230223084324.9076-3-lucas.tanure@collabora.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/cs35l41.c

index f2b5032daa6ae07250c16be1a427e4a44710d2e4..c006364e5335554e7106083b73f4205c8c919479 100644 (file)
@@ -369,6 +369,16 @@ static void cs35l41_boost_enable(struct cs35l41_private *cs35l41, unsigned int e
        }
 }
 
+
+static void cs35l41_error_release(struct cs35l41_private *cs35l41, unsigned int irq_err_bit,
+                                 unsigned int rel_err_bit)
+{
+       regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1, irq_err_bit);
+       regmap_write(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, 0);
+       regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, rel_err_bit, rel_err_bit);
+       regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, rel_err_bit, 0);
+}
+
 static irqreturn_t cs35l41_irq(int irq, void *data)
 {
        struct cs35l41_private *cs35l41 = data;
@@ -405,54 +415,26 @@ static irqreturn_t cs35l41_irq(int irq, void *data)
         */
        if (status[0] & CS35L41_AMP_SHORT_ERR) {
                dev_crit_ratelimited(cs35l41->dev, "Amp short error\n");
-               regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1,
-                            CS35L41_AMP_SHORT_ERR);
-               regmap_write(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, 0);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_AMP_SHORT_ERR_RLS,
-                                  CS35L41_AMP_SHORT_ERR_RLS);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_AMP_SHORT_ERR_RLS, 0);
+               cs35l41_error_release(cs35l41, CS35L41_AMP_SHORT_ERR, CS35L41_AMP_SHORT_ERR_RLS);
                ret = IRQ_HANDLED;
        }
 
        if (status[0] & CS35L41_TEMP_WARN) {
                dev_crit_ratelimited(cs35l41->dev, "Over temperature warning\n");
-               regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1,
-                            CS35L41_TEMP_WARN);
-               regmap_write(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, 0);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_TEMP_WARN_ERR_RLS,
-                                  CS35L41_TEMP_WARN_ERR_RLS);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_TEMP_WARN_ERR_RLS, 0);
+               cs35l41_error_release(cs35l41, CS35L41_TEMP_WARN, CS35L41_TEMP_WARN_ERR_RLS);
                ret = IRQ_HANDLED;
        }
 
        if (status[0] & CS35L41_TEMP_ERR) {
                dev_crit_ratelimited(cs35l41->dev, "Over temperature error\n");
-               regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1,
-                            CS35L41_TEMP_ERR);
-               regmap_write(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, 0);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_TEMP_ERR_RLS,
-                                  CS35L41_TEMP_ERR_RLS);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_TEMP_ERR_RLS, 0);
+               cs35l41_error_release(cs35l41, CS35L41_TEMP_ERR, CS35L41_TEMP_ERR_RLS);
                ret = IRQ_HANDLED;
        }
 
        if (status[0] & CS35L41_BST_OVP_ERR) {
                dev_crit_ratelimited(cs35l41->dev, "VBST Over Voltage error\n");
                cs35l41_boost_enable(cs35l41, 0);
-               regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1,
-                            CS35L41_BST_OVP_ERR);
-               regmap_write(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, 0);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_BST_OVP_ERR_RLS,
-                                  CS35L41_BST_OVP_ERR_RLS);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_BST_OVP_ERR_RLS, 0);
+               cs35l41_error_release(cs35l41, CS35L41_BST_OVP_ERR, CS35L41_BST_OVP_ERR_RLS);
                cs35l41_boost_enable(cs35l41, 1);
                ret = IRQ_HANDLED;
        }
@@ -460,14 +442,7 @@ static irqreturn_t cs35l41_irq(int irq, void *data)
        if (status[0] & CS35L41_BST_DCM_UVP_ERR) {
                dev_crit_ratelimited(cs35l41->dev, "DCM VBST Under Voltage Error\n");
                cs35l41_boost_enable(cs35l41, 0);
-               regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1,
-                            CS35L41_BST_DCM_UVP_ERR);
-               regmap_write(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, 0);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_BST_UVP_ERR_RLS,
-                                  CS35L41_BST_UVP_ERR_RLS);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_BST_UVP_ERR_RLS, 0);
+               cs35l41_error_release(cs35l41, CS35L41_BST_DCM_UVP_ERR, CS35L41_BST_UVP_ERR_RLS);
                cs35l41_boost_enable(cs35l41, 1);
                ret = IRQ_HANDLED;
        }
@@ -475,14 +450,7 @@ static irqreturn_t cs35l41_irq(int irq, void *data)
        if (status[0] & CS35L41_BST_SHORT_ERR) {
                dev_crit_ratelimited(cs35l41->dev, "LBST error: powering off!\n");
                cs35l41_boost_enable(cs35l41, 0);
-               regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1,
-                            CS35L41_BST_SHORT_ERR);
-               regmap_write(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN, 0);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_BST_SHORT_ERR_RLS,
-                                  CS35L41_BST_SHORT_ERR_RLS);
-               regmap_update_bits(cs35l41->regmap, CS35L41_PROTECT_REL_ERR_IGN,
-                                  CS35L41_BST_SHORT_ERR_RLS, 0);
+               cs35l41_error_release(cs35l41, CS35L41_BST_SHORT_ERR, CS35L41_BST_SHORT_ERR_RLS);
                cs35l41_boost_enable(cs35l41, 1);
                ret = IRQ_HANDLED;
        }