clk_ast2500.c 787 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. int ast_get_clk(struct udevice **devp)
  10. {
  11. return uclass_get_device_by_driver(UCLASS_CLK,
  12. DM_GET_DRIVER(aspeed_ast2500_scu), devp);
  13. }
  14. void *ast_get_scu(void)
  15. {
  16. struct ast2500_clk_priv *priv;
  17. struct udevice *dev;
  18. int ret;
  19. ret = ast_get_clk(&dev);
  20. if (ret)
  21. return ERR_PTR(ret);
  22. priv = dev_get_priv(dev);
  23. return priv->scu;
  24. }
  25. void ast_scu_unlock(struct ast2500_scu *scu)
  26. {
  27. writel(SCU_UNLOCK_VALUE, &scu->protection_key);
  28. while (!readl(&scu->protection_key))
  29. ;
  30. }
  31. void ast_scu_lock(struct ast2500_scu *scu)
  32. {
  33. writel(~SCU_UNLOCK_VALUE, &scu->protection_key);
  34. while (readl(&scu->protection_key))
  35. ;
  36. }