mips-cpc.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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_t mips_cpc_default_phys_base(void);
  25. /**
  26. * mips_cpc_phys_base - retrieve the physical base address of the CPC
  27. *
  28. * This function returns the physical base address of the Cluster Power
  29. * Controller memory mapped registers, or 0 if no Cluster Power Controller
  30. * is present. It may be overriden by individual platforms which determine
  31. * this address in a different way.
  32. */
  33. extern phys_t __weak mips_cpc_phys_base(void);
  34. /**
  35. * mips_cpc_probe - probe for a Cluster Power Controller
  36. *
  37. * Attempt to detect the presence of a Cluster Power Controller. Returns 0 if
  38. * a CPC is successfully detected, else -errno.
  39. */
  40. #ifdef CONFIG_MIPS_CPC
  41. extern int mips_cpc_probe(void);
  42. #else
  43. static inline int mips_cpc_probe(void)
  44. {
  45. return -ENODEV;
  46. }
  47. #endif
  48. /**
  49. * mips_cpc_present - determine whether a Cluster Power Controller is present
  50. *
  51. * Returns true if a CPC is present in the system, else false.
  52. */
  53. static inline bool mips_cpc_present(void)
  54. {
  55. #ifdef CONFIG_MIPS_CPC
  56. return mips_cpc_base != NULL;
  57. #else
  58. return false;
  59. #endif
  60. }
  61. /* Offsets from the CPC base address to various control blocks */
  62. #define MIPS_CPC_GCB_OFS 0x0000
  63. #define MIPS_CPC_CLCB_OFS 0x2000
  64. #define MIPS_CPC_COCB_OFS 0x4000
  65. /* Macros to ease the creation of register access functions */
  66. #define BUILD_CPC_R_(name, off) \
  67. static inline u32 *addr_cpc_##name(void) \
  68. { \
  69. return (u32 *)(mips_cpc_base + (off)); \
  70. } \
  71. \
  72. static inline u32 read_cpc_##name(void) \
  73. { \
  74. return __raw_readl(mips_cpc_base + (off)); \
  75. }
  76. #define BUILD_CPC__W(name, off) \
  77. static inline void write_cpc_##name(u32 value) \
  78. { \
  79. __raw_writel(value, mips_cpc_base + (off)); \
  80. }
  81. #define BUILD_CPC_RW(name, off) \
  82. BUILD_CPC_R_(name, off) \
  83. BUILD_CPC__W(name, off)
  84. #define BUILD_CPC_Cx_R_(name, off) \
  85. BUILD_CPC_R_(cl_##name, MIPS_CPC_CLCB_OFS + (off)) \
  86. BUILD_CPC_R_(co_##name, MIPS_CPC_COCB_OFS + (off))
  87. #define BUILD_CPC_Cx__W(name, off) \
  88. BUILD_CPC__W(cl_##name, MIPS_CPC_CLCB_OFS + (off)) \
  89. BUILD_CPC__W(co_##name, MIPS_CPC_COCB_OFS + (off))
  90. #define BUILD_CPC_Cx_RW(name, off) \
  91. BUILD_CPC_Cx_R_(name, off) \
  92. BUILD_CPC_Cx__W(name, off)
  93. /* GCB register accessor functions */
  94. BUILD_CPC_RW(access, MIPS_CPC_GCB_OFS + 0x00)
  95. BUILD_CPC_RW(seqdel, MIPS_CPC_GCB_OFS + 0x08)
  96. BUILD_CPC_RW(rail, MIPS_CPC_GCB_OFS + 0x10)
  97. BUILD_CPC_RW(resetlen, MIPS_CPC_GCB_OFS + 0x18)
  98. BUILD_CPC_R_(revision, MIPS_CPC_GCB_OFS + 0x20)
  99. /* Core Local & Core Other accessor functions */
  100. BUILD_CPC_Cx_RW(cmd, 0x00)
  101. BUILD_CPC_Cx_RW(stat_conf, 0x08)
  102. BUILD_CPC_Cx_RW(other, 0x10)
  103. /* CPC_Cx_CMD register fields */
  104. #define CPC_Cx_CMD_SHF 0
  105. #define CPC_Cx_CMD_MSK (_ULCAST_(0xf) << 0)
  106. #define CPC_Cx_CMD_CLOCKOFF (_ULCAST_(0x1) << 0)
  107. #define CPC_Cx_CMD_PWRDOWN (_ULCAST_(0x2) << 0)
  108. #define CPC_Cx_CMD_PWRUP (_ULCAST_(0x3) << 0)
  109. #define CPC_Cx_CMD_RESET (_ULCAST_(0x4) << 0)
  110. /* CPC_Cx_STAT_CONF register fields */
  111. #define CPC_Cx_STAT_CONF_PWRUPE_SHF 23
  112. #define CPC_Cx_STAT_CONF_PWRUPE_MSK (_ULCAST_(0x1) << 23)
  113. #define CPC_Cx_STAT_CONF_SEQSTATE_SHF 19
  114. #define CPC_Cx_STAT_CONF_SEQSTATE_MSK (_ULCAST_(0xf) << 19)
  115. #define CPC_Cx_STAT_CONF_SEQSTATE_D0 (_ULCAST_(0x0) << 19)
  116. #define CPC_Cx_STAT_CONF_SEQSTATE_U0 (_ULCAST_(0x1) << 19)
  117. #define CPC_Cx_STAT_CONF_SEQSTATE_U1 (_ULCAST_(0x2) << 19)
  118. #define CPC_Cx_STAT_CONF_SEQSTATE_U2 (_ULCAST_(0x3) << 19)
  119. #define CPC_Cx_STAT_CONF_SEQSTATE_U3 (_ULCAST_(0x4) << 19)
  120. #define CPC_Cx_STAT_CONF_SEQSTATE_U4 (_ULCAST_(0x5) << 19)
  121. #define CPC_Cx_STAT_CONF_SEQSTATE_U5 (_ULCAST_(0x6) << 19)
  122. #define CPC_Cx_STAT_CONF_SEQSTATE_U6 (_ULCAST_(0x7) << 19)
  123. #define CPC_Cx_STAT_CONF_SEQSTATE_D1 (_ULCAST_(0x8) << 19)
  124. #define CPC_Cx_STAT_CONF_SEQSTATE_D3 (_ULCAST_(0x9) << 19)
  125. #define CPC_Cx_STAT_CONF_SEQSTATE_D2 (_ULCAST_(0xa) << 19)
  126. #define CPC_Cx_STAT_CONF_CLKGAT_IMPL_SHF 17
  127. #define CPC_Cx_STAT_CONF_CLKGAT_IMPL_MSK (_ULCAST_(0x1) << 17)
  128. #define CPC_Cx_STAT_CONF_PWRDN_IMPL_SHF 16
  129. #define CPC_Cx_STAT_CONF_PWRDN_IMPL_MSK (_ULCAST_(0x1) << 16)
  130. #define CPC_Cx_STAT_CONF_EJTAG_PROBE_SHF 15
  131. #define CPC_Cx_STAT_CONF_EJTAG_PROBE_MSK (_ULCAST_(0x1) << 15)
  132. /* CPC_Cx_OTHER register fields */
  133. #define CPC_Cx_OTHER_CORENUM_SHF 16
  134. #define CPC_Cx_OTHER_CORENUM_MSK (_ULCAST_(0xff) << 16)
  135. #ifdef CONFIG_MIPS_CPC
  136. /**
  137. * mips_cpc_lock_other - lock access to another core
  138. * core: the other core to be accessed
  139. *
  140. * Call before operating upon a core via the 'other' register region in
  141. * order to prevent the region being moved during access. Must be followed
  142. * by a call to mips_cpc_unlock_other.
  143. */
  144. extern void mips_cpc_lock_other(unsigned int core);
  145. /**
  146. * mips_cpc_unlock_other - unlock access to another core
  147. *
  148. * Call after operating upon another core via the 'other' register region.
  149. * Must be called after mips_cpc_lock_other.
  150. */
  151. extern void mips_cpc_unlock_other(void);
  152. #else /* !CONFIG_MIPS_CPC */
  153. static inline void mips_cpc_lock_other(unsigned int core) { }
  154. static inline void mips_cpc_unlock_other(void) { }
  155. #endif /* !CONFIG_MIPS_CPC */
  156. #endif /* __MIPS_ASM_MIPS_CPC_H__ */