prcm.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * linux/arch/arm/mach-omap2/prcm.c
  3. *
  4. * OMAP 24xx Power Reset and Clock Management (PRCM) functions
  5. *
  6. * Copyright (C) 2005 Nokia Corporation
  7. *
  8. * Written by Tony Lindgren <tony.lindgren@nokia.com>
  9. *
  10. * Some pieces of code Copyright (C) 2005 Texas Instruments, Inc.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/clk.h>
  19. #include <linux/io.h>
  20. #include <mach/common.h>
  21. #include <mach/prcm.h>
  22. #include "clock.h"
  23. #include "prm.h"
  24. #include "prm-regbits-24xx.h"
  25. static void __iomem *prm_base;
  26. static void __iomem *cm_base;
  27. u32 omap_prcm_get_reset_sources(void)
  28. {
  29. /* XXX This presumably needs modification for 34XX */
  30. return prm_read_mod_reg(WKUP_MOD, RM_RSTST) & 0x7f;
  31. }
  32. EXPORT_SYMBOL(omap_prcm_get_reset_sources);
  33. /* Resets clock rates and reboots the system. Only called from system.h */
  34. void omap_prcm_arch_reset(char mode)
  35. {
  36. s16 prcm_offs;
  37. omap2_clk_prepare_for_reboot();
  38. if (cpu_is_omap24xx())
  39. prcm_offs = WKUP_MOD;
  40. else if (cpu_is_omap34xx())
  41. prcm_offs = OMAP3430_GR_MOD;
  42. else
  43. WARN_ON(1);
  44. prm_set_mod_reg_bits(OMAP_RST_DPLL3, prcm_offs, RM_RSTCTRL);
  45. }
  46. static inline u32 __omap_prcm_read(void __iomem *base, s16 module, u16 reg)
  47. {
  48. BUG_ON(!base);
  49. return __raw_readl(base + module + reg);
  50. }
  51. static inline void __omap_prcm_write(u32 value, void __iomem *base,
  52. s16 module, u16 reg)
  53. {
  54. BUG_ON(!base);
  55. __raw_writel(value, base + module + reg);
  56. }
  57. /* Read a register in a PRM module */
  58. u32 prm_read_mod_reg(s16 module, u16 idx)
  59. {
  60. return __omap_prcm_read(prm_base, module, idx);
  61. }
  62. EXPORT_SYMBOL(prm_read_mod_reg);
  63. /* Write into a register in a PRM module */
  64. void prm_write_mod_reg(u32 val, s16 module, u16 idx)
  65. {
  66. __omap_prcm_write(val, prm_base, module, idx);
  67. }
  68. EXPORT_SYMBOL(prm_write_mod_reg);
  69. /* Read-modify-write a register in a PRM module. Caller must lock */
  70. u32 prm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
  71. {
  72. u32 v;
  73. v = prm_read_mod_reg(module, idx);
  74. v &= ~mask;
  75. v |= bits;
  76. prm_write_mod_reg(v, module, idx);
  77. return v;
  78. }
  79. EXPORT_SYMBOL(prm_rmw_mod_reg_bits);
  80. /* Read a register in a CM module */
  81. u32 cm_read_mod_reg(s16 module, u16 idx)
  82. {
  83. return __omap_prcm_read(cm_base, module, idx);
  84. }
  85. EXPORT_SYMBOL(cm_read_mod_reg);
  86. /* Write into a register in a CM module */
  87. void cm_write_mod_reg(u32 val, s16 module, u16 idx)
  88. {
  89. __omap_prcm_write(val, cm_base, module, idx);
  90. }
  91. EXPORT_SYMBOL(cm_write_mod_reg);
  92. /* Read-modify-write a register in a CM module. Caller must lock */
  93. u32 cm_rmw_mod_reg_bits(u32 mask, u32 bits, s16 module, s16 idx)
  94. {
  95. u32 v;
  96. v = cm_read_mod_reg(module, idx);
  97. v &= ~mask;
  98. v |= bits;
  99. cm_write_mod_reg(v, module, idx);
  100. return v;
  101. }
  102. EXPORT_SYMBOL(cm_rmw_mod_reg_bits);
  103. void __init omap2_set_globals_prcm(struct omap_globals *omap2_globals)
  104. {
  105. prm_base = omap2_globals->prm;
  106. cm_base = omap2_globals->cm;
  107. }