owl-sps-helper.c 909 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Actions Semi Owl Smart Power System (SPS) shared helpers
  4. *
  5. * Copyright 2012 Actions Semi Inc.
  6. * Author: Actions Semi, Inc.
  7. *
  8. * Copyright (c) 2017 Andreas Färber
  9. */
  10. #include <linux/delay.h>
  11. #include <linux/io.h>
  12. #include <linux/soc/actions/owl-sps.h>
  13. #define OWL_SPS_PG_CTL 0x0
  14. int owl_sps_set_pg(void __iomem *base, u32 pwr_mask, u32 ack_mask, bool enable)
  15. {
  16. u32 val;
  17. bool ack;
  18. int timeout;
  19. val = readl(base + OWL_SPS_PG_CTL);
  20. ack = val & ack_mask;
  21. if (ack == enable)
  22. return 0;
  23. if (enable)
  24. val |= pwr_mask;
  25. else
  26. val &= ~pwr_mask;
  27. writel(val, base + OWL_SPS_PG_CTL);
  28. for (timeout = 5000; timeout > 0; timeout -= 50) {
  29. val = readl(base + OWL_SPS_PG_CTL);
  30. if ((val & ack_mask) == (enable ? ack_mask : 0))
  31. break;
  32. udelay(50);
  33. }
  34. if (timeout <= 0)
  35. return -ETIMEDOUT;
  36. udelay(10);
  37. return 0;
  38. }
  39. EXPORT_SYMBOL_GPL(owl_sps_set_pg);