From f917a54ff7b441685d4a19601993f174c08ebf11 Mon Sep 17 00:00:00 2001 From: Mark Yao Date: Mon, 19 Jun 2017 15:29:29 +0800 Subject: [PATCH] drm/rockchip: protect loader clocks Change-Id: Ie9217de35ea1dc11d99b6340fc9f6ecc27ba33c8 Signed-off-by: Mark Yao --- drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c index 855bed63652e..770a565ec6c5 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -676,6 +677,55 @@ err_unlock: if (ret) dev_err(drm_dev->dev, "failed to show loader logo\n"); } + +static const char *const loader_protect_clocks[] __initconst = { + "hclk_vio", + "aclk_vio", + "aclk_vio0", +}; + +static struct clk **loader_clocks __initdata; +static int __init rockchip_clocks_loader_protect(void) +{ + int nclocks = ARRAY_SIZE(loader_protect_clocks); + struct clk *clk; + int i; + + loader_clocks = kcalloc(nclocks, sizeof(void *), GFP_KERNEL); + if (!loader_clocks) + return -ENOMEM; + + for (i = 0; i < nclocks; i++) { + clk = __clk_lookup(loader_protect_clocks[i]); + + if (clk) { + loader_clocks[i] = clk; + clk_prepare_enable(clk); + } + } + + return 0; +} +fs_initcall(rockchip_clocks_loader_protect); + +static int __init rockchip_clocks_loader_unprotect(void) +{ + int i; + + if (!loader_clocks) + return -ENODEV; + + for (i = 0; i < ARRAY_SIZE(loader_protect_clocks); i++) { + struct clk *clk = loader_clocks[i]; + + if (clk) + clk_disable_unprepare(clk); + } + kfree(loader_clocks); + + return 0; +} +late_initcall_sync(rockchip_clocks_loader_unprotect); #endif /* -- 2.34.1