hwrng: ingenic: simplify the code
Subsystems (2)
Simplify the ingenic-trng driver a bit. Switch to devm_clk_get_enabled and devm_hwrng_register. Remove some unused code.
The changes were compile-tested only (I don't have this hardware).
Martin Kaiser (7):
hwrng: ingenic - enable compile testing
hwrng: ingenic - remove two unused defines
hwrng: ingenic - remove dead assignments
hwrng: ingenic - use devm_clk_get_enabled
hwrng: ingenic - use dev_err_probe in error paths
hwrng: ingenic - don't disable the rng in ingenic_trng_remove
hwrng: ingenic - switch to device managed registration
drivers/char/hw_random/Kconfig | 3 +- drivers/char/hw_random/ingenic-trng.c | 57 ++++++--------------------- 2 files changed, 12 insertions(+), 48 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/7 hwrng: ingenic - enable compile testing
Enable compile testing for the ingenic-trng driver.
Remove the dependency on HW_RANDOM. The ingenic-trng config section is under "if HW_RANDOM".
--- drivers/char/hw_random/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/char/hw_random/Kconfig +1 -2
@@ -271,8 +271,7 @@ config HW_RANDOM_INGENIC_RNG config HW_RANDOM_INGENIC_TRNG tristate "Ingenic True Random Number Generator support" - depends on HW_RANDOM - depends on MACH_X1830 + depends on MACH_X1830 || COMPILE_TEST default HW_RANDOM help This driver provides kernel-side support for the True Random Number Generator
Signature · 1 line
2.30.2
PATCH 2/7 hwrng: ingenic - remove two unused defines
In reply to Martin KaiserRemove two defines which are not used in the ingenic-trng driver's code.
--- drivers/char/hw_random/ingenic-trng.c | 2 -- 1 file changed, 2 deletions(-)
drivers/char/hw_random/ingenic-trng.c +0 -2
@@ -22,8 +22,6 @@#define TRNG_REG_STATUS_OFFSET 0x08/* bits within the CFG register */ -#define CFG_RDY_CLR BIT(12) -#define CFG_INT_MASK BIT(11)#define CFG_GEN_EN BIT(0)/* bits within the STATUS register */
Signature · 1 line
2.30.2
PATCH 3/7 hwrng: ingenic - remove dead assignments
In reply to Martin KaiserDon't assign a value to ret if we're about to return from the probe function and ret's value is not used.
--- drivers/char/hw_random/ingenic-trng.c | 2 -- 1 file changed, 2 deletions(-)
drivers/char/hw_random/ingenic-trng.c +0 -2
@@ -86,13 +86,11 @@ static int ingenic_trng_probe(struct platform_device *pdev) trng->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (trng->base)) {pr_err ("%s: Failed to map DTRNG registers\n" , __func__); - ret =PTR_ERR (trng->base);return PTR_ERR (trng->base); } trng->clk =devm_clk_get (&pdev->dev,NULL );if (IS_ERR (trng->clk)) { - ret =PTR_ERR (trng->clk);pr_crit ("%s: Cannot get DTRNG clock\n" , __func__);return PTR_ERR (trng->clk); }
Signature · 1 line
2.30.2
PATCH 4/7 hwrng: ingenic - use devm_clk_get_enabled
In reply to Martin KaiserUse devm_clk_get_enabled in the ingenic-trng driver. We don't have to disable and unprepare the clock any more in error paths or in the remove function.
--- drivers/char/hw_random/ingenic-trng.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)
drivers/char/hw_random/ingenic-trng.c +6 -18
@@ -29,7 +29,6 @@struct ingenic_trng {void __iomem *base; -struct clk *clk;struct hwrng rng; };
@@ -77,6 +76,7 @@ static int ingenic_trng_read(struct hwrng *rng, void *buf, size_t max, bool waitstatic int ingenic_trng_probe (struct platform_device *pdev) {struct ingenic_trng *trng; +struct clk *clk;int ret; trng =devm_kzalloc (&pdev->dev,sizeof (*trng),GFP_KERNEL );
@@ -89,16 +89,10 @@ static int ingenic_trng_probe(struct platform_device *pdev)return PTR_ERR (trng->base); } - trng->clk =devm_clk_get (&pdev->dev,NULL ); -if (IS_ERR (trng->clk)) { -pr_crit ("%s: Cannot get DTRNG clock\n" , __func__); -return PTR_ERR (trng->clk); - } - - ret =clk_prepare_enable (trng->clk); -if (ret) { -pr_crit ("%s: Unable to enable DTRNG clock\n" , __func__); -return ret; + clk =devm_clk_get_enabled (&pdev->dev,NULL ); +if (IS_ERR (clk)) { +pr_crit ("%s: Cannot get and enable DTRNG clock\n" , __func__); +return PTR_ERR (clk); } trng->rng.name = pdev->name;
@@ -109,17 +103,13 @@ static int ingenic_trng_probe(struct platform_device *pdev) ret =hwrng_register (&trng->rng);if (ret) {dev_err (&pdev->dev,"Failed to register hwrng\n" ); - goto err_unprepare_clk; +return ret; }platform_set_drvdata (pdev, trng);dev_info (&pdev->dev,"Ingenic DTRNG driver registered\n" );return 0 ; - -err_unprepare_clk: -clk_disable_unprepare (trng->clk); -return ret; }static int ingenic_trng_remove (struct platform_device *pdev)
@@ -133,8 +123,6 @@ static int ingenic_trng_remove(struct platform_device *pdev) ctrl &= ~CFG_GEN_EN ;writel (ctrl, trng->base +TRNG_REG_CFG_OFFSET ); -clk_disable_unprepare (trng->clk); -return 0 ; }
Signature · 1 line
2.30.2
PATCH 5/7 hwrng: ingenic - use dev_err_probe in error paths
In reply to Martin KaiserUse dev_err_probe in error paths to make the code a bit shorter.
--- drivers/char/hw_random/ingenic-trng.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/char/hw_random/ingenic-trng.c +8 -12
@@ -84,16 +84,14 @@ static int ingenic_trng_probe(struct platform_device *pdev)return -ENOMEM ; trng->base =devm_platform_ioremap_resource (pdev,0 ); -if (IS_ERR (trng->base)) { -pr_err ("%s: Failed to map DTRNG registers\n" , __func__); -return PTR_ERR (trng->base); - } +if (IS_ERR (trng->base)) +return dev_err_probe (&pdev->dev,PTR_ERR (trng->base), +"%s: Failed to map DTRNG registers\n" , __func__); clk =devm_clk_get_enabled (&pdev->dev,NULL ); -if (IS_ERR (clk)) { -pr_crit ("%s: Cannot get and enable DTRNG clock\n" , __func__); -return PTR_ERR (clk); - } +if (IS_ERR (clk)) +return dev_err_probe (&pdev->dev,PTR_ERR (clk), +"%s: Cannot get and enable DTRNG clock\n" , __func__); trng->rng.name = pdev->name; trng->rng.init = ingenic_trng_init;
@@ -101,10 +99,8 @@ static int ingenic_trng_probe(struct platform_device *pdev) trng->rng.read = ingenic_trng_read; ret =hwrng_register (&trng->rng); -if (ret) { -dev_err (&pdev->dev,"Failed to register hwrng\n" ); -return ret; - } +if (ret) +return dev_err_probe (&pdev->dev, ret,"Failed to register hwrng\n" );platform_set_drvdata (pdev, trng);
Signature · 1 line
2.30.2
PATCH 6/7 hwrng: ingenic - don't disable the rng in ingenic_trng_remove
In reply to Martin KaiserThere's no need to disable the rng in ingenic_trng_remove.
The driver's init function sets the CFG_GEN_EN bit to enable the rng. The cleanup function clears CFG_GEN_EN to revert this.
The remove function calls hwrng_unregister. If the ingenic-trng is not the current rng at this point, CFG_GEN_EN has already been cleared. If the ingenic-trng is the current rng, drop_current_rng will call the cleanup function.
--- drivers/char/hw_random/ingenic-trng.c | 5 ----- 1 file changed, 5 deletions(-)
drivers/char/hw_random/ingenic-trng.c +0 -5
@@ -111,14 +111,9 @@ static int ingenic_trng_probe(struct platform_device *pdev)static int ingenic_trng_remove (struct platform_device *pdev) {struct ingenic_trng *trng =platform_get_drvdata (pdev); -unsigned int ctrl;hwrng_unregister (&trng->rng); - ctrl =readl (trng->base +TRNG_REG_CFG_OFFSET ); - ctrl &= ~CFG_GEN_EN ; -writel (ctrl, trng->base +TRNG_REG_CFG_OFFSET ); -return 0 ; }
Signature · 1 line
2.30.2
PATCH 7/7 hwrng: ingenic - switch to device managed registration
In reply to Martin KaiserCall devm_hwrng_register for device managed registration of the ingenic-trng driver. ingenic_trng_remove can then be deleted.
--- drivers/char/hw_random/ingenic-trng.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/char/hw_random/ingenic-trng.c +1 -11
@@ -98,7 +98,7 @@ static int ingenic_trng_probe(struct platform_device *pdev) trng->rng.cleanup = ingenic_trng_cleanup; trng->rng.read = ingenic_trng_read; - ret =hwrng_register (&trng->rng); + ret =devm_hwrng_register (&pdev->dev, &trng->rng);if (ret)return dev_err_probe (&pdev->dev, ret,"Failed to register hwrng\n" );
@@ -108,15 +108,6 @@ static int ingenic_trng_probe(struct platform_device *pdev)return 0 ; } -static int ingenic_trng_remove (struct platform_device *pdev) -{ -struct ingenic_trng *trng =platform_get_drvdata (pdev); - -hwrng_unregister (&trng->rng); - -return 0 ; -} -static const struct of_device_id ingenic_trng_of_match[] = { { .compatible ="ingenic,x1830-dtrng" }, {/* sentinel */ }
@@ -125,7 +116,6 @@ MODULE_DEVICE_TABLE(of, ingenic_trng_of_match);static struct platform_driver ingenic_trng_driver = { .probe = ingenic_trng_probe, - .remove = ingenic_trng_remove, .driver = { .name ="ingenic-trng" , .of_match_table = ingenic_trng_of_match,
Signature · 1 line
2.30.2
Herbert Xu
maintainerQuoted 14 lines · Martin Kaiser
Simplify the ingenic-trng driver a bit. Switch to
devm_clk_get_enabledanddevm_hwrng_register. Remove some unused code.The changes were compile-tested only (I don't have this hardware).
Martin Kaiser (7):
hwrng: ingenic - enable compile testing
hwrng: ingenic - remove two unused defines
hwrng: ingenic - remove dead assignments
hwrng: ingenic - usedevm_clk_get_enabled
hwrng: ingenic - usedev_err_probein error paths
hwrng: ingenic - don't disable the rng iningenic_trng_remove
hwrng: ingenic - switch to device managed registration
Quoted 6 lines
drivers/char/hw_random/Kconfig | 3 +- drivers/char/hw_random/ingenic-trng.c | 57 ++++++--------------------- 2 files changed, 12 insertions(+), 48 deletions(-)Signature · 1 line
2.30.2
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt