Commit 70dd444a authored by Corentin Labbe's avatar Corentin Labbe Committed by Herbert Xu

crypto: sun4i-ss - simplify enable/disable of the device

This patch regroups resource enabling/disabling in dedicated function.
This simplify error handling and will permit to support power
management.
Signed-off-by: default avatarCorentin Labbe <clabbe.montjoie@gmail.com>
Acked-by: default avatarMaxime Ripard <mripard@kernel.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 6a97a99d
...@@ -223,6 +223,45 @@ static struct sun4i_ss_alg_template ss_algs[] = { ...@@ -223,6 +223,45 @@ static struct sun4i_ss_alg_template ss_algs[] = {
#endif #endif
}; };
static void sun4i_ss_disable(struct sun4i_ss_ctx *ss)
{
if (ss->reset)
reset_control_assert(ss->reset);
clk_disable_unprepare(ss->ssclk);
clk_disable_unprepare(ss->busclk);
}
static int sun4i_ss_enable(struct sun4i_ss_ctx *ss)
{
int err;
err = clk_prepare_enable(ss->busclk);
if (err) {
dev_err(ss->dev, "Cannot prepare_enable busclk\n");
goto err_enable;
}
err = clk_prepare_enable(ss->ssclk);
if (err) {
dev_err(ss->dev, "Cannot prepare_enable ssclk\n");
goto err_enable;
}
if (ss->reset) {
err = reset_control_deassert(ss->reset);
if (err) {
dev_err(ss->dev, "Cannot deassert reset control\n");
goto err_enable;
}
}
return err;
err_enable:
sun4i_ss_disable(ss);
return err;
}
static int sun4i_ss_probe(struct platform_device *pdev) static int sun4i_ss_probe(struct platform_device *pdev)
{ {
u32 v; u32 v;
...@@ -269,17 +308,9 @@ static int sun4i_ss_probe(struct platform_device *pdev) ...@@ -269,17 +308,9 @@ static int sun4i_ss_probe(struct platform_device *pdev)
ss->reset = NULL; ss->reset = NULL;
} }
/* Enable both clocks */ err = sun4i_ss_enable(ss);
err = clk_prepare_enable(ss->busclk); if (err)
if (err) { goto error_enable;
dev_err(&pdev->dev, "Cannot prepare_enable busclk\n");
return err;
}
err = clk_prepare_enable(ss->ssclk);
if (err) {
dev_err(&pdev->dev, "Cannot prepare_enable ssclk\n");
goto error_ssclk;
}
/* /*
* Check that clock have the correct rates given in the datasheet * Check that clock have the correct rates given in the datasheet
...@@ -288,16 +319,7 @@ static int sun4i_ss_probe(struct platform_device *pdev) ...@@ -288,16 +319,7 @@ static int sun4i_ss_probe(struct platform_device *pdev)
err = clk_set_rate(ss->ssclk, cr_mod); err = clk_set_rate(ss->ssclk, cr_mod);
if (err) { if (err) {
dev_err(&pdev->dev, "Cannot set clock rate to ssclk\n"); dev_err(&pdev->dev, "Cannot set clock rate to ssclk\n");
goto error_clk; goto error_enable;
}
/* Deassert reset if we have a reset control */
if (ss->reset) {
err = reset_control_deassert(ss->reset);
if (err) {
dev_err(&pdev->dev, "Cannot deassert reset control\n");
goto error_clk;
}
} }
/* /*
...@@ -387,12 +409,8 @@ static int sun4i_ss_probe(struct platform_device *pdev) ...@@ -387,12 +409,8 @@ static int sun4i_ss_probe(struct platform_device *pdev)
break; break;
} }
} }
if (ss->reset) error_enable:
reset_control_assert(ss->reset); sun4i_ss_disable(ss);
error_clk:
clk_disable_unprepare(ss->ssclk);
error_ssclk:
clk_disable_unprepare(ss->busclk);
return err; return err;
} }
...@@ -416,10 +434,7 @@ static int sun4i_ss_remove(struct platform_device *pdev) ...@@ -416,10 +434,7 @@ static int sun4i_ss_remove(struct platform_device *pdev)
} }
writel(0, ss->base + SS_CTL); writel(0, ss->base + SS_CTL);
if (ss->reset) sun4i_ss_disable(ss);
reset_control_assert(ss->reset);
clk_disable_unprepare(ss->busclk);
clk_disable_unprepare(ss->ssclk);
return 0; return 0;
} }
......
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