watchdog.h 4.1 KB

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