clk_ast2500.c 810 B

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