mips-cpc.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Copyright (C) 2013 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@imgtec.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #ifndef __MIPS_ASM_MIPS_CPC_H__
  11. #define __MIPS_ASM_MIPS_CPC_H__
  12. #include <linux/io.h>
  13. #include <linux/types.h>
  14. /* The base address of the CPC registers */
  15. extern void __iomem *mips_cpc_base;
  16. /**
  17. * mips_cpc_default_phys_base - retrieve the default physical base address of
  18. * the CPC
  19. *
  20. * Returns the default physical base address of the Cluster Power Controller
  21. * memory mapped registers. This is platform dependant & must therefore be
  22. * implemented per-platform.
  23. */
  24. extern phys_addr_t mips_cpc_default_phys_base(void);
  25. /**
  26. * mips_cpc_probe - probe for a Cluster Power Controller
  27. *
  28. * Attempt to detect the presence of a Cluster Power Controller. Returns 0 if
  29. * a CPC is successfully detected, else -errno.
  30. */
  31. #ifdef CONFIG_MIPS_CPC
  32. extern int mips_cpc_probe(void);
  33. #else
  34. static inline int mips_cpc_probe(void)
  35. {
  36. return -ENODEV;
  37. }
  38. #endif
  39. /**
  40. * mips_cpc_present - determine whether a Cluster Power Controller is present
  41. *
  42. * Returns true if a CPC is present in the system, else false.
  43. */
  44. static inline bool mips_cpc_present(void)
  45. {
  46. #ifdef CONFIG_MIPS_CPC
  47. return mips_cpc_base != NULL;
  48. #else
  49. return false;
  50. #endif
  51. }
  52. /* Offsets from the CPC base address to various control blocks */
  53. #define MIPS_CPC_GCB_OFS 0x0000
  54. #define MIPS_CPC_CLCB_OFS 0x2000
  55. #define MIPS_CPC_COCB_OFS 0x4000
  56. /* Macros to ease the creation of register access functions */
  57. #define BUILD_CPC_R_(name, off) \
  58. static inline u32 *addr_cpc_##name(void) \
  59. { \
  60. return (u32 *)(mips_cpc_base + (off)); \
  61. } \
  62. \
  63. static inline u32 read_cpc_##name(void) \
  64. { \
  65. return __raw_readl(mips_cpc_base + (off)); \
  66. }
  67. #define BUILD_CPC__W(name, off) \
  68. static inline void write_cpc_##name(u32 value) \
  69. { \
  70. __raw_writel(value, mips_cpc_base + (off)); \
  71. }
  72. #define BUILD_CPC_RW(name, off) \
  73. BUILD_CPC_R_(name, off) \
  74. BUILD_CPC__W(name, off)
  75. #define BUILD_CPC_Cx_R_(name, off) \
  76. BUILD_CPC_R_(cl_##name, MIPS_CPC_CLCB_OFS + (off)) \
  77. BUILD_CPC_R_(co_##name, MIPS_CPC_COCB_OFS + (off))
  78. #define BUILD_CPC_Cx__W(name, off) \
  79. BUILD_CPC__W(cl_##name, MIPS_CPC_CLCB_OFS + (off)) \
  80. BUILD_CPC__W(co_##name, MIPS_CPC_COCB_OFS + (off))
  81. #define BUILD_CPC_Cx_RW(name, off) \
  82. BUILD_CPC_Cx_R_(name, off) \
  83. BUILD_CPC_Cx__W(name, off)
  84. /* GCB register accessor functions */
  85. BUILD_CPC_RW(access, MIPS_CPC_GCB_OFS + 0x00)
  86. BUILD_CPC_RW(seqdel, MIPS_CPC_GCB_OFS + 0x08)
  87. BUILD_CPC_RW(rail, MIPS_CPC_GCB_OFS + 0x10)
  88. BUILD_CPC_RW(resetlen, MIPS_CPC_GCB_OFS + 0x18)
  89. BUILD_CPC_R_(revision, MIPS_CPC_GCB_OFS + 0x20)
  90. /* Core Local & Core Other accessor functions */
  91. BUILD_CPC_Cx_RW(cmd, 0x00)
  92. BUILD_CPC_Cx_RW(stat_conf, 0x08)
  93. BUILD_CPC_Cx_RW(other, 0x10)
  94. BUILD_CPC_Cx_RW(vp_stop, 0x20)
  95. BUILD_CPC_Cx_RW(vp_run, 0x28)
  96. BUILD_CPC_Cx_RW(vp_running, 0x30)
  97. /* CPC_Cx_CMD register fields */
  98. #define CPC_Cx_CMD_SHF 0
  99. #define CPC_Cx_CMD_MSK (_ULCAST_(0xf) << 0)
  100. #define CPC_Cx_CMD_CLOCKOFF (_ULCAST_(0x1) << 0)
  101. #define CPC_Cx_CMD_PWRDOWN (_ULCAST_(0x2) << 0)
  102. #define CPC_Cx_CMD_PWRUP (_ULCAST_(0x3) << 0)
  103. #define CPC_Cx_CMD_RESET (_ULCAST_(0x4) << 0)
  104. /* CPC_Cx_STAT_CONF register fields */
  105. #define CPC_Cx_STAT_CONF_PWRUPE_SHF 23
  106. #define CPC_Cx_STAT_CONF_PWRUPE_MSK (_ULCAST_(0x1) << 23)
  107. #define CPC_Cx_STAT_CONF_SEQSTATE_SHF 19
  108. #define CPC_Cx_STAT_CONF_SEQSTATE_MSK (_ULCAST_(0xf) << 19)
  109. #define CPC_Cx_STAT_CONF_SEQSTATE_D0 (_ULCAST_(0x0) << 19)
  110. #define CPC_Cx_STAT_CONF_SEQSTATE_U0 (_ULCAST_(0x1) << 19)
  111. #define CPC_Cx_STAT_CONF_SEQSTATE_U1 (_ULCAST_(0x2) << 19)
  112. #define CPC_Cx_STAT_CONF_SEQSTATE_U2 (_ULCAST_(0x3) << 19)
  113. #define CPC_Cx_STAT_CONF_SEQSTATE_U3 (_ULCAST_(0x4) << 19)
  114. #define CPC_Cx_STAT_CONF_SEQSTATE_U4 (_ULCAST_(0x5) << 19)
  115. #define CPC_Cx_STAT_CONF_SEQSTATE_U5 (_ULCAST_(0x6) << 19)
  116. #define CPC_Cx_STAT_CONF_SEQSTATE_U6 (_ULCAST_(0x7) << 19)
  117. #define CPC_Cx_STAT_CONF_SEQSTATE_D1 (_ULCAST_(0x8) << 19)
  118. #define CPC_Cx_STAT_CONF_SEQSTATE_D3 (_ULCAST_(0x9) << 19)
  119. #define CPC_Cx_STAT_CONF_SEQSTATE_D2 (_ULCAST_(0xa) << 19)
  120. #define CPC_Cx_STAT_CONF_CLKGAT_IMPL_SHF 17
  121. #define CPC_Cx_STAT_CONF_CLKGAT_IMPL_MSK (_ULCAST_(0x1) << 17)
  122. #define CPC_Cx_STAT_CONF_PWRDN_IMPL_SHF 16
  123. #define CPC_Cx_STAT_CONF_PWRDN_IMPL_MSK (_ULCAST_(0x1) << 16)
  124. #define CPC_Cx_STAT_CONF_EJTAG_PROBE_SHF 15
  125. #define CPC_Cx_STAT_CONF_EJTAG_PROBE_MSK (_ULCAST_(0x1) << 15)
  126. /* CPC_Cx_OTHER register fields */
  127. #define CPC_Cx_OTHER_CORENUM_SHF 16
  128. #define CPC_Cx_OTHER_CORENUM_MSK (_ULCAST_(0xff) << 16)
  129. #ifdef CONFIG_MIPS_CPC
  130. /**
  131. * mips_cpc_lock_other - lock access to another core
  132. * core: the other core to be accessed
  133. *
  134. * Call before operating upon a core via the 'other' register region in
  135. * order to prevent the region being moved during access. Must be called
  136. * within the bounds of a mips_cm_{lock,unlock}_other pair, and followed
  137. * by a call to mips_cpc_unlock_other.
  138. */
  139. extern void mips_cpc_lock_other(unsigned int core);
  140. /**
  141. * mips_cpc_unlock_other - unlock access to another core
  142. *
  143. * Call after operating upon another core via the 'other' register region.
  144. * Must be called after mips_cpc_lock_other.
  145. */
  146. extern void mips_cpc_unlock_other(void);
  147. #else /* !CONFIG_MIPS_CPC */
  148. static inline void mips_cpc_lock_other(unsigned int core) { }
  149. static inline void mips_cpc_unlock_other(void) { }
  150. #endif /* !CONFIG_MIPS_CPC */
  151. #endif /* __MIPS_ASM_MIPS_CPC_H__ */