cm.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * OMAP2/3 CM module functions
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Paul Walmsley
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/delay.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/list.h>
  17. #include <linux/errno.h>
  18. #include <linux/err.h>
  19. #include <linux/io.h>
  20. #include <asm/atomic.h>
  21. #include "cm.h"
  22. #include "cm-regbits-24xx.h"
  23. #include "cm-regbits-34xx.h"
  24. /* MAX_MODULE_READY_TIME: max milliseconds for module to leave idle */
  25. #define MAX_MODULE_READY_TIME 20000
  26. static const u8 cm_idlest_offs[] = {
  27. CM_IDLEST1, CM_IDLEST2, OMAP2430_CM_IDLEST3
  28. };
  29. /**
  30. * omap2_cm_wait_idlest_ready - wait for a module to leave idle or standby
  31. * @prcm_mod: PRCM module offset
  32. * @idlest_id: CM_IDLESTx register ID (i.e., x = 1, 2, 3)
  33. * @idlest_shift: shift of the bit in the CM_IDLEST* register to check
  34. *
  35. * XXX document
  36. */
  37. int omap2_cm_wait_module_ready(s16 prcm_mod, u8 idlest_id, u8 idlest_shift)
  38. {
  39. int ena = 0, i = 0;
  40. u8 cm_idlest_reg;
  41. u32 mask;
  42. if (!idlest_id || (idlest_id > ARRAY_SIZE(cm_idlest_offs)))
  43. return -EINVAL;
  44. cm_idlest_reg = cm_idlest_offs[idlest_id - 1];
  45. if (cpu_is_omap24xx())
  46. ena = idlest_shift;
  47. else if (cpu_is_omap34xx())
  48. ena = 0;
  49. else
  50. BUG();
  51. mask = 1 << idlest_shift;
  52. /* XXX should be OMAP2 CM */
  53. while (((cm_read_mod_reg(prcm_mod, cm_idlest_reg) & mask) != ena) &&
  54. (i++ < MAX_MODULE_READY_TIME))
  55. udelay(1);
  56. return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
  57. }