Commit be9457f1 authored by Lucas Tanure's avatar Lucas Tanure Committed by Mark Brown

ASoC: cs35l41: Refactor error release code

Add cs35l41_error_release function to handle error release sequences.
Signed-off-by: default avatarLucas Tanure <lucas.tanure@collabora.com>
Acked-by: default avatarCharles Keepax <ckeepax@opensource.cirrus.com>
Reviewed-by: default avatarDavid Rhodes <david.rhodes@cirrus.com>
Link: https://lore.kernel.org/r/20230223084324.9076-3-lucas.tanure@collabora.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 4658de99
...@@ -369,6 +369,16 @@ static void cs35l41_boost_enable(struct cs35l41_private *cs35l41, unsigned int e ...@@ -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) static irqreturn_t cs35l41_irq(int irq, void *data)
{ {
struct cs35l41_private *cs35l41 = data; struct cs35l41_private *cs35l41 = data;
...@@ -405,54 +415,26 @@ static irqreturn_t cs35l41_irq(int irq, void *data) ...@@ -405,54 +415,26 @@ static irqreturn_t cs35l41_irq(int irq, void *data)
*/ */
if (status[0] & CS35L41_AMP_SHORT_ERR) { if (status[0] & CS35L41_AMP_SHORT_ERR) {
dev_crit_ratelimited(cs35l41->dev, "Amp short error\n"); dev_crit_ratelimited(cs35l41->dev, "Amp short error\n");
regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1, cs35l41_error_release(cs35l41, CS35L41_AMP_SHORT_ERR, CS35L41_AMP_SHORT_ERR_RLS);
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);
ret = IRQ_HANDLED; ret = IRQ_HANDLED;
} }
if (status[0] & CS35L41_TEMP_WARN) { if (status[0] & CS35L41_TEMP_WARN) {
dev_crit_ratelimited(cs35l41->dev, "Over temperature warning\n"); dev_crit_ratelimited(cs35l41->dev, "Over temperature warning\n");
regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1, cs35l41_error_release(cs35l41, CS35L41_TEMP_WARN, CS35L41_TEMP_WARN_ERR_RLS);
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);
ret = IRQ_HANDLED; ret = IRQ_HANDLED;
} }
if (status[0] & CS35L41_TEMP_ERR) { if (status[0] & CS35L41_TEMP_ERR) {
dev_crit_ratelimited(cs35l41->dev, "Over temperature error\n"); dev_crit_ratelimited(cs35l41->dev, "Over temperature error\n");
regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1, cs35l41_error_release(cs35l41, CS35L41_TEMP_ERR, CS35L41_TEMP_ERR_RLS);
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);
ret = IRQ_HANDLED; ret = IRQ_HANDLED;
} }
if (status[0] & CS35L41_BST_OVP_ERR) { if (status[0] & CS35L41_BST_OVP_ERR) {
dev_crit_ratelimited(cs35l41->dev, "VBST Over Voltage error\n"); dev_crit_ratelimited(cs35l41->dev, "VBST Over Voltage error\n");
cs35l41_boost_enable(cs35l41, 0); cs35l41_boost_enable(cs35l41, 0);
regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1, cs35l41_error_release(cs35l41, CS35L41_BST_OVP_ERR, CS35L41_BST_OVP_ERR_RLS);
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_boost_enable(cs35l41, 1); cs35l41_boost_enable(cs35l41, 1);
ret = IRQ_HANDLED; ret = IRQ_HANDLED;
} }
...@@ -460,14 +442,7 @@ static irqreturn_t cs35l41_irq(int irq, void *data) ...@@ -460,14 +442,7 @@ static irqreturn_t cs35l41_irq(int irq, void *data)
if (status[0] & CS35L41_BST_DCM_UVP_ERR) { if (status[0] & CS35L41_BST_DCM_UVP_ERR) {
dev_crit_ratelimited(cs35l41->dev, "DCM VBST Under Voltage Error\n"); dev_crit_ratelimited(cs35l41->dev, "DCM VBST Under Voltage Error\n");
cs35l41_boost_enable(cs35l41, 0); cs35l41_boost_enable(cs35l41, 0);
regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1, cs35l41_error_release(cs35l41, CS35L41_BST_DCM_UVP_ERR, CS35L41_BST_UVP_ERR_RLS);
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_boost_enable(cs35l41, 1); cs35l41_boost_enable(cs35l41, 1);
ret = IRQ_HANDLED; ret = IRQ_HANDLED;
} }
...@@ -475,14 +450,7 @@ static irqreturn_t cs35l41_irq(int irq, void *data) ...@@ -475,14 +450,7 @@ static irqreturn_t cs35l41_irq(int irq, void *data)
if (status[0] & CS35L41_BST_SHORT_ERR) { if (status[0] & CS35L41_BST_SHORT_ERR) {
dev_crit_ratelimited(cs35l41->dev, "LBST error: powering off!\n"); dev_crit_ratelimited(cs35l41->dev, "LBST error: powering off!\n");
cs35l41_boost_enable(cs35l41, 0); cs35l41_boost_enable(cs35l41, 0);
regmap_write(cs35l41->regmap, CS35L41_IRQ1_STATUS1, cs35l41_error_release(cs35l41, CS35L41_BST_SHORT_ERR, CS35L41_BST_SHORT_ERR_RLS);
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_boost_enable(cs35l41, 1); cs35l41_boost_enable(cs35l41, 1);
ret = IRQ_HANDLED; ret = IRQ_HANDLED;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment