owl-sps-helper.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Actions Semi Owl Smart Power System (SPS) shared helpers
  3. *
  4. * Copyright 2012 Actions Semi Inc.
  5. * Author: Actions Semi, Inc.
  6. *
  7. * Copyright (c) 2017 Andreas Färber
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/io.h>
  16. #define OWL_SPS_PG_CTL 0x0
  17. int owl_sps_set_pg(void __iomem *base, u32 pwr_mask, u32 ack_mask, bool enable)
  18. {
  19. u32 val;
  20. bool ack;
  21. int timeout;
  22. val = readl(base + OWL_SPS_PG_CTL);
  23. ack = val & ack_mask;
  24. if (ack == enable)
  25. return 0;
  26. if (enable)
  27. val |= pwr_mask;
  28. else
  29. val &= ~pwr_mask;
  30. writel(val, base + OWL_SPS_PG_CTL);
  31. for (timeout = 5000; timeout > 0; timeout -= 50) {
  32. val = readl(base + OWL_SPS_PG_CTL);
  33. if ((val & ack_mask) == (enable ? ack_mask : 0))
  34. break;
  35. udelay(50);
  36. }
  37. if (timeout <= 0)
  38. return -ETIMEDOUT;
  39. udelay(10);
  40. return 0;
  41. }
  42. EXPORT_SYMBOL_GPL(owl_sps_set_pg);