cm4xxx.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * OMAP4 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-4xxx.h"
  23. /* XXX move this to cm.h */
  24. /* MAX_MODULE_READY_TIME: max milliseconds for module to leave idle */
  25. #define MAX_MODULE_READY_TIME 20000
  26. /*
  27. * OMAP4_PRCM_CM_CLKCTRL_IDLEST_MASK: isolates the IDLEST field in the
  28. * CM_CLKCTRL register.
  29. */
  30. #define OMAP4_PRCM_CM_CLKCTRL_IDLEST_MASK (0x2 << 16)
  31. /*
  32. * OMAP4 prcm_mod u32 fields contain packed data: the CM ID in bit 16 and
  33. * the PRCM module offset address (from the CM module base) in bits 15-0.
  34. */
  35. #define OMAP4_PRCM_MOD_CM_ID_SHIFT 16
  36. #define OMAP4_PRCM_MOD_OFFS_MASK 0xffff
  37. /**
  38. * omap4_cm_wait_idlest_ready - wait for a module to leave idle or standby
  39. * @prcm_mod: PRCM module offset (XXX example)
  40. * @prcm_dev_offs: PRCM device offset (e.g. MCASP XXX example)
  41. *
  42. * XXX document
  43. */
  44. int omap4_cm_wait_idlest_ready(u32 prcm_mod, u8 prcm_dev_offs)
  45. {
  46. int i = 0;
  47. u8 cm_id;
  48. u16 prcm_mod_offs;
  49. u32 mask = OMAP4_PRCM_CM_CLKCTRL_IDLEST_MASK;
  50. cm_id = prcm_mod >> OMAP4_PRCM_MOD_CM_ID_SHIFT;
  51. prcm_mod_offs = prcm_mod & OMAP4_PRCM_MOD_OFFS_MASK;
  52. while (((omap4_cm_read_mod_reg(cm_id, prcm_mod_offs, prcm_dev_offs,
  53. OMAP4_CM_CLKCTRL_DREG) & mask) != 0) &&
  54. (i++ < MAX_MODULE_READY_TIME))
  55. udelay(1);
  56. return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
  57. }