watchdog.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* SPDX-License-Identifier: GPL-2.0+
  2. *
  3. * include/asm-sh/watchdog.h
  4. *
  5. * Copyright (C) 2002, 2003 Paul Mundt
  6. * Copyright (C) 2009 Siemens AG
  7. * Copyright (C) 2009 Valentin Sitdikov
  8. */
  9. #ifndef __ASM_SH_WATCHDOG_H
  10. #define __ASM_SH_WATCHDOG_H
  11. #include <linux/types.h>
  12. #include <linux/io.h>
  13. #define WTCNT_HIGH 0x5a
  14. #define WTCSR_HIGH 0xa5
  15. #define WTCSR_CKS2 0x04
  16. #define WTCSR_CKS1 0x02
  17. #define WTCSR_CKS0 0x01
  18. #include <cpu/watchdog.h>
  19. /*
  20. * See cpu-sh2/watchdog.h for explanation of this stupidity..
  21. */
  22. #ifndef WTCNT_R
  23. # define WTCNT_R WTCNT
  24. #endif
  25. #ifndef WTCSR_R
  26. # define WTCSR_R WTCSR
  27. #endif
  28. /*
  29. * CKS0-2 supports a number of clock division ratios. At the time the watchdog
  30. * is enabled, it defaults to a 41 usec overflow period .. we overload this to
  31. * something a little more reasonable, and really can't deal with anything
  32. * lower than WTCSR_CKS_1024, else we drop back into the usec range.
  33. *
  34. * Clock Division Ratio Overflow Period
  35. * --------------------------------------------
  36. * 1/32 (initial value) 41 usecs
  37. * 1/64 82 usecs
  38. * 1/128 164 usecs
  39. * 1/256 328 usecs
  40. * 1/512 656 usecs
  41. * 1/1024 1.31 msecs
  42. * 1/2048 2.62 msecs
  43. * 1/4096 5.25 msecs
  44. */
  45. #define WTCSR_CKS_32 0x00
  46. #define WTCSR_CKS_64 0x01
  47. #define WTCSR_CKS_128 0x02
  48. #define WTCSR_CKS_256 0x03
  49. #define WTCSR_CKS_512 0x04
  50. #define WTCSR_CKS_1024 0x05
  51. #define WTCSR_CKS_2048 0x06
  52. #define WTCSR_CKS_4096 0x07
  53. #if defined(CONFIG_CPU_SUBTYPE_SH7785) || defined(CONFIG_CPU_SUBTYPE_SH7780)
  54. /**
  55. * sh_wdt_read_cnt - Read from Counter
  56. * Reads back the WTCNT value.
  57. */
  58. static inline __u32 sh_wdt_read_cnt(void)
  59. {
  60. return __raw_readl(WTCNT_R);
  61. }
  62. /**
  63. * sh_wdt_write_cnt - Write to Counter
  64. * @val: Value to write
  65. *
  66. * Writes the given value @val to the lower byte of the timer counter.
  67. * The upper byte is set manually on each write.
  68. */
  69. static inline void sh_wdt_write_cnt(__u32 val)
  70. {
  71. __raw_writel((WTCNT_HIGH << 24) | (__u32)val, WTCNT);
  72. }
  73. /**
  74. * sh_wdt_write_bst - Write to Counter
  75. * @val: Value to write
  76. *
  77. * Writes the given value @val to the lower byte of the timer counter.
  78. * The upper byte is set manually on each write.
  79. */
  80. static inline void sh_wdt_write_bst(__u32 val)
  81. {
  82. __raw_writel((WTBST_HIGH << 24) | (__u32)val, WTBST);
  83. }
  84. /**
  85. * sh_wdt_read_csr - Read from Control/Status Register
  86. *
  87. * Reads back the WTCSR value.
  88. */
  89. static inline __u32 sh_wdt_read_csr(void)
  90. {
  91. return __raw_readl(WTCSR_R);
  92. }
  93. /**
  94. * sh_wdt_write_csr - Write to Control/Status Register
  95. * @val: Value to write
  96. *
  97. * Writes the given value @val to the lower byte of the control/status
  98. * register. The upper byte is set manually on each write.
  99. */
  100. static inline void sh_wdt_write_csr(__u32 val)
  101. {
  102. __raw_writel((WTCSR_HIGH << 24) | (__u32)val, WTCSR);
  103. }
  104. #else
  105. /**
  106. * sh_wdt_read_cnt - Read from Counter
  107. * Reads back the WTCNT value.
  108. */
  109. static inline __u8 sh_wdt_read_cnt(void)
  110. {
  111. return __raw_readb(WTCNT_R);
  112. }
  113. /**
  114. * sh_wdt_write_cnt - Write to Counter
  115. * @val: Value to write
  116. *
  117. * Writes the given value @val to the lower byte of the timer counter.
  118. * The upper byte is set manually on each write.
  119. */
  120. static inline void sh_wdt_write_cnt(__u8 val)
  121. {
  122. __raw_writew((WTCNT_HIGH << 8) | (__u16)val, WTCNT);
  123. }
  124. /**
  125. * sh_wdt_read_csr - Read from Control/Status Register
  126. *
  127. * Reads back the WTCSR value.
  128. */
  129. static inline __u8 sh_wdt_read_csr(void)
  130. {
  131. return __raw_readb(WTCSR_R);
  132. }
  133. /**
  134. * sh_wdt_write_csr - Write to Control/Status Register
  135. * @val: Value to write
  136. *
  137. * Writes the given value @val to the lower byte of the control/status
  138. * register. The upper byte is set manually on each write.
  139. */
  140. static inline void sh_wdt_write_csr(__u8 val)
  141. {
  142. __raw_writew((WTCSR_HIGH << 8) | (__u16)val, WTCSR);
  143. }
  144. #endif /* CONFIG_CPU_SUBTYPE_SH7785 || CONFIG_CPU_SUBTYPE_SH7780 */
  145. #endif /* __ASM_SH_WATCHDOG_H */