1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2016 Google, Inc
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <asm/io.h>
9 #include <asm/arch/scu_ast2500.h>
10 #include <linux/err.h>
11 
ast_get_clk(struct udevice ** devp)12 int ast_get_clk(struct udevice **devp)
13 {
14 	return uclass_get_device_by_driver(UCLASS_CLK,
15 			DM_DRIVER_GET(aspeed_ast2500_scu), devp);
16 }
17 
ast_get_scu(void)18 void *ast_get_scu(void)
19 {
20 	struct ast2500_clk_priv *priv;
21 	struct udevice *dev;
22 	int ret;
23 
24 	ret = ast_get_clk(&dev);
25 	if (ret)
26 		return ERR_PTR(ret);
27 
28 	priv = dev_get_priv(dev);
29 
30 	return priv->scu;
31 }
32 
ast_scu_unlock(struct ast2500_scu * scu)33 void ast_scu_unlock(struct ast2500_scu *scu)
34 {
35 	writel(SCU_UNLOCK_VALUE, &scu->protection_key);
36 	while (!readl(&scu->protection_key))
37 		;
38 }
39 
ast_scu_lock(struct ast2500_scu * scu)40 void ast_scu_lock(struct ast2500_scu *scu)
41 {
42 	writel(~SCU_UNLOCK_VALUE, &scu->protection_key);
43 	while (readl(&scu->protection_key))
44 		;
45 }
46