cm2xxx_3xxx.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/types.h>
  13. #include <linux/delay.h>
  14. #include <linux/spinlock.h>
  15. #include <linux/list.h>
  16. #include <linux/errno.h>
  17. #include <linux/err.h>
  18. #include <linux/io.h>
  19. #include <plat/common.h>
  20. #include "cm.h"
  21. #include "cm2xxx_3xxx.h"
  22. #include "cm-regbits-24xx.h"
  23. #include "cm-regbits-34xx.h"
  24. static const u8 cm_idlest_offs[] = {
  25. CM_IDLEST1, CM_IDLEST2, OMAP2430_CM_IDLEST3
  26. };
  27. u32 cm_read_mod_reg(s16 module, u16 idx)
  28. {
  29. return __raw_readl(cm_base + module + idx);
  30. }
  31. void cm_write_mod_reg(u32 val, s16 module, u16 idx)
  32. {
  33. __raw_writel(val, cm_base + module + idx);
  34. }
  35. /* Read-modify-write a register in a CM module. Caller must lock */
  36. u32 cm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
  37. {
  38. u32 v;
  39. v = cm_read_mod_reg(module, idx);
  40. v &= ~mask;
  41. v |= bits;
  42. cm_write_mod_reg(v, module, idx);
  43. return v;
  44. }
  45. u32 cm_set_mod_reg_bits(u32 bits, s16 module, s16 idx)
  46. {
  47. return cm_rmw_mod_reg_bits(bits, bits, module, idx);
  48. }
  49. u32 cm_clear_mod_reg_bits(u32 bits, s16 module, s16 idx)
  50. {
  51. return cm_rmw_mod_reg_bits(bits, 0x0, module, idx);
  52. }
  53. /**
  54. * omap2_cm_wait_idlest_ready - wait for a module to leave idle or standby
  55. * @prcm_mod: PRCM module offset
  56. * @idlest_id: CM_IDLESTx register ID (i.e., x = 1, 2, 3)
  57. * @idlest_shift: shift of the bit in the CM_IDLEST* register to check
  58. *
  59. * XXX document
  60. */
  61. int omap2_cm_wait_module_ready(s16 prcm_mod, u8 idlest_id, u8 idlest_shift)
  62. {
  63. int ena = 0, i = 0;
  64. u8 cm_idlest_reg;
  65. u32 mask;
  66. if (!idlest_id || (idlest_id > ARRAY_SIZE(cm_idlest_offs)))
  67. return -EINVAL;
  68. cm_idlest_reg = cm_idlest_offs[idlest_id - 1];
  69. mask = 1 << idlest_shift;
  70. if (cpu_is_omap24xx())
  71. ena = mask;
  72. else if (cpu_is_omap34xx())
  73. ena = 0;
  74. else
  75. BUG();
  76. omap_test_timeout(((cm_read_mod_reg(prcm_mod, cm_idlest_reg) & mask) == ena),
  77. MAX_MODULE_READY_TIME, i);
  78. return (i < MAX_MODULE_READY_TIME) ? 0 : -EBUSY;
  79. }