gptimers.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * gptimers.h - Blackfin General Purpose Timer structs/defines/prototypes
  3. *
  4. * Copyright (c) 2005-2008 Analog Devices Inc.
  5. * Copyright (C) 2005 John DeHority
  6. * Copyright (C) 2006 Hella Aglaia GmbH (awe@aglaia-gmbh.de)
  7. *
  8. * Licensed under the GPL-2.
  9. */
  10. #ifndef _BLACKFIN_TIMERS_H_
  11. #define _BLACKFIN_TIMERS_H_
  12. #include <linux/types.h>
  13. #include <asm/blackfin.h>
  14. /*
  15. * BF51x/BF52x/BF537: 8 timers:
  16. */
  17. #if defined(CONFIG_BF51x) || defined(CONFIG_BF52x) || defined(BF537_FAMILY)
  18. # define MAX_BLACKFIN_GPTIMERS 8
  19. # define TIMER0_GROUP_REG TIMER_ENABLE
  20. #endif
  21. /*
  22. * BF54x: 11 timers (BF542: 8 timers):
  23. */
  24. #if defined(CONFIG_BF54x)
  25. # ifdef CONFIG_BF542
  26. # define MAX_BLACKFIN_GPTIMERS 8
  27. # else
  28. # define MAX_BLACKFIN_GPTIMERS 11
  29. # define TIMER8_GROUP_REG TIMER_ENABLE1
  30. # define TIMER_GROUP2 1
  31. # endif
  32. # define TIMER0_GROUP_REG TIMER_ENABLE0
  33. #endif
  34. /*
  35. * BF561: 12 timers:
  36. */
  37. #if defined(CONFIG_BF561)
  38. # define MAX_BLACKFIN_GPTIMERS 12
  39. # define TIMER0_GROUP_REG TMRS8_ENABLE
  40. # define TIMER8_GROUP_REG TMRS4_ENABLE
  41. # define TIMER_GROUP2 1
  42. #endif
  43. /*
  44. * BF609: 8 timers:
  45. */
  46. #if defined(CONFIG_BF60x)
  47. # define MAX_BLACKFIN_GPTIMERS 8
  48. # define TIMER0_GROUP_REG TIMER_RUN
  49. #endif
  50. /*
  51. * All others: 3 timers:
  52. */
  53. #define TIMER_GROUP1 0
  54. #if !defined(MAX_BLACKFIN_GPTIMERS)
  55. # define MAX_BLACKFIN_GPTIMERS 3
  56. # define TIMER0_GROUP_REG TIMER_ENABLE
  57. #endif
  58. #define BLACKFIN_GPTIMER_IDMASK ((1UL << MAX_BLACKFIN_GPTIMERS) - 1)
  59. #define BFIN_TIMER_OCTET(x) ((x) >> 3)
  60. /* used in masks for timer_enable() and timer_disable() */
  61. #define TIMER0bit 0x0001 /* 0001b */
  62. #define TIMER1bit 0x0002 /* 0010b */
  63. #define TIMER2bit 0x0004 /* 0100b */
  64. #define TIMER3bit 0x0008
  65. #define TIMER4bit 0x0010
  66. #define TIMER5bit 0x0020
  67. #define TIMER6bit 0x0040
  68. #define TIMER7bit 0x0080
  69. #define TIMER8bit 0x0100
  70. #define TIMER9bit 0x0200
  71. #define TIMER10bit 0x0400
  72. #define TIMER11bit 0x0800
  73. #define TIMER0_id 0
  74. #define TIMER1_id 1
  75. #define TIMER2_id 2
  76. #define TIMER3_id 3
  77. #define TIMER4_id 4
  78. #define TIMER5_id 5
  79. #define TIMER6_id 6
  80. #define TIMER7_id 7
  81. #define TIMER8_id 8
  82. #define TIMER9_id 9
  83. #define TIMER10_id 10
  84. #define TIMER11_id 11
  85. /* associated timers for ppi framesync: */
  86. #if defined(CONFIG_BF561)
  87. # define FS0_1_TIMER_ID TIMER8_id
  88. # define FS0_2_TIMER_ID TIMER9_id
  89. # define FS1_1_TIMER_ID TIMER10_id
  90. # define FS1_2_TIMER_ID TIMER11_id
  91. # define FS0_1_TIMER_BIT TIMER8bit
  92. # define FS0_2_TIMER_BIT TIMER9bit
  93. # define FS1_1_TIMER_BIT TIMER10bit
  94. # define FS1_2_TIMER_BIT TIMER11bit
  95. # undef FS1_TIMER_ID
  96. # undef FS2_TIMER_ID
  97. # undef FS1_TIMER_BIT
  98. # undef FS2_TIMER_BIT
  99. #else
  100. # define FS1_TIMER_ID TIMER0_id
  101. # define FS2_TIMER_ID TIMER1_id
  102. # define FS1_TIMER_BIT TIMER0bit
  103. # define FS2_TIMER_BIT TIMER1bit
  104. #endif
  105. #ifdef CONFIG_BF60x
  106. /*
  107. * Timer Configuration Register Bits
  108. */
  109. #define TIMER_EMU_RUN 0x8000
  110. #define TIMER_BPER_EN 0x4000
  111. #define TIMER_BWID_EN 0x2000
  112. #define TIMER_BDLY_EN 0x1000
  113. #define TIMER_OUT_DIS 0x0800
  114. #define TIMER_TIN_SEL 0x0400
  115. #define TIMER_CLK_SEL 0x0300
  116. #define TIMER_CLK_SCLK 0x0000
  117. #define TIMER_CLK_ALT_CLK0 0x0100
  118. #define TIMER_CLK_ALT_CLK1 0x0300
  119. #define TIMER_PULSE_HI 0x0080
  120. #define TIMER_SLAVE_TRIG 0x0040
  121. #define TIMER_IRQ_MODE 0x0030
  122. #define TIMER_IRQ_ACT_EDGE 0x0000
  123. #define TIMER_IRQ_DLY 0x0010
  124. #define TIMER_IRQ_WID_DLY 0x0020
  125. #define TIMER_IRQ_PER 0x0030
  126. #define TIMER_MODE 0x000f
  127. #define TIMER_MODE_WDOG_P 0x0008
  128. #define TIMER_MODE_WDOG_W 0x0009
  129. #define TIMER_MODE_PWM_CONT 0x000c
  130. #define TIMER_MODE_PWM 0x000d
  131. #define TIMER_MODE_WDTH 0x000a
  132. #define TIMER_MODE_WDTH_D 0x000b
  133. #define TIMER_MODE_EXT_CLK 0x000e
  134. #define TIMER_MODE_PININT 0x000f
  135. /*
  136. * Timer Status Register Bits
  137. */
  138. #define TIMER_STATUS_TIMIL0 0x0001
  139. #define TIMER_STATUS_TIMIL1 0x0002
  140. #define TIMER_STATUS_TIMIL2 0x0004
  141. #define TIMER_STATUS_TIMIL3 0x0008
  142. #define TIMER_STATUS_TIMIL4 0x0010
  143. #define TIMER_STATUS_TIMIL5 0x0020
  144. #define TIMER_STATUS_TIMIL6 0x0040
  145. #define TIMER_STATUS_TIMIL7 0x0080
  146. #define TIMER_STATUS_TOVF0 0x0001 /* timer 0 overflow error */
  147. #define TIMER_STATUS_TOVF1 0x0002
  148. #define TIMER_STATUS_TOVF2 0x0004
  149. #define TIMER_STATUS_TOVF3 0x0008
  150. #define TIMER_STATUS_TOVF4 0x0010
  151. #define TIMER_STATUS_TOVF5 0x0020
  152. #define TIMER_STATUS_TOVF6 0x0040
  153. #define TIMER_STATUS_TOVF7 0x0080
  154. /*
  155. * Timer Slave Enable Status : write 1 to clear
  156. */
  157. #define TIMER_STATUS_TRUN0 0x0001
  158. #define TIMER_STATUS_TRUN1 0x0002
  159. #define TIMER_STATUS_TRUN2 0x0004
  160. #define TIMER_STATUS_TRUN3 0x0008
  161. #define TIMER_STATUS_TRUN4 0x0010
  162. #define TIMER_STATUS_TRUN5 0x0020
  163. #define TIMER_STATUS_TRUN6 0x0040
  164. #define TIMER_STATUS_TRUN7 0x0080
  165. #else
  166. /*
  167. * Timer Configuration Register Bits
  168. */
  169. #define TIMER_ERR 0xC000
  170. #define TIMER_ERR_OVFL 0x4000
  171. #define TIMER_ERR_PROG_PER 0x8000
  172. #define TIMER_ERR_PROG_PW 0xC000
  173. #define TIMER_EMU_RUN 0x0200
  174. #define TIMER_TOGGLE_HI 0x0100
  175. #define TIMER_CLK_SEL 0x0080
  176. #define TIMER_OUT_DIS 0x0040
  177. #define TIMER_TIN_SEL 0x0020
  178. #define TIMER_IRQ_ENA 0x0010
  179. #define TIMER_PERIOD_CNT 0x0008
  180. #define TIMER_PULSE_HI 0x0004
  181. #define TIMER_MODE 0x0003
  182. #define TIMER_MODE_PWM 0x0001
  183. #define TIMER_MODE_WDTH 0x0002
  184. #define TIMER_MODE_EXT_CLK 0x0003
  185. /*
  186. * Timer Status Register Bits
  187. */
  188. #define TIMER_STATUS_TIMIL0 0x0001
  189. #define TIMER_STATUS_TIMIL1 0x0002
  190. #define TIMER_STATUS_TIMIL2 0x0004
  191. #define TIMER_STATUS_TIMIL3 0x00000008
  192. #define TIMER_STATUS_TIMIL4 0x00010000
  193. #define TIMER_STATUS_TIMIL5 0x00020000
  194. #define TIMER_STATUS_TIMIL6 0x00040000
  195. #define TIMER_STATUS_TIMIL7 0x00080000
  196. #define TIMER_STATUS_TIMIL8 0x0001
  197. #define TIMER_STATUS_TIMIL9 0x0002
  198. #define TIMER_STATUS_TIMIL10 0x0004
  199. #define TIMER_STATUS_TIMIL11 0x0008
  200. #define TIMER_STATUS_TOVF0 0x0010 /* timer 0 overflow error */
  201. #define TIMER_STATUS_TOVF1 0x0020
  202. #define TIMER_STATUS_TOVF2 0x0040
  203. #define TIMER_STATUS_TOVF3 0x00000080
  204. #define TIMER_STATUS_TOVF4 0x00100000
  205. #define TIMER_STATUS_TOVF5 0x00200000
  206. #define TIMER_STATUS_TOVF6 0x00400000
  207. #define TIMER_STATUS_TOVF7 0x00800000
  208. #define TIMER_STATUS_TOVF8 0x0010
  209. #define TIMER_STATUS_TOVF9 0x0020
  210. #define TIMER_STATUS_TOVF10 0x0040
  211. #define TIMER_STATUS_TOVF11 0x0080
  212. /*
  213. * Timer Slave Enable Status : write 1 to clear
  214. */
  215. #define TIMER_STATUS_TRUN0 0x1000
  216. #define TIMER_STATUS_TRUN1 0x2000
  217. #define TIMER_STATUS_TRUN2 0x4000
  218. #define TIMER_STATUS_TRUN3 0x00008000
  219. #define TIMER_STATUS_TRUN4 0x10000000
  220. #define TIMER_STATUS_TRUN5 0x20000000
  221. #define TIMER_STATUS_TRUN6 0x40000000
  222. #define TIMER_STATUS_TRUN7 0x80000000
  223. #define TIMER_STATUS_TRUN 0xF000F000
  224. #define TIMER_STATUS_TRUN8 0x1000
  225. #define TIMER_STATUS_TRUN9 0x2000
  226. #define TIMER_STATUS_TRUN10 0x4000
  227. #define TIMER_STATUS_TRUN11 0x8000
  228. #endif
  229. /* The actual gptimer API */
  230. void set_gptimer_pwidth(unsigned int timer_id, uint32_t width);
  231. uint32_t get_gptimer_pwidth(unsigned int timer_id);
  232. void set_gptimer_period(unsigned int timer_id, uint32_t period);
  233. uint32_t get_gptimer_period(unsigned int timer_id);
  234. #ifdef CONFIG_BF60x
  235. void set_gptimer_delay(unsigned int timer_id, uint32_t delay);
  236. uint32_t get_gptimer_delay(unsigned int timer_id);
  237. #endif
  238. uint32_t get_gptimer_count(unsigned int timer_id);
  239. int get_gptimer_intr(unsigned int timer_id);
  240. void clear_gptimer_intr(unsigned int timer_id);
  241. int get_gptimer_over(unsigned int timer_id);
  242. void clear_gptimer_over(unsigned int timer_id);
  243. void set_gptimer_config(unsigned int timer_id, uint16_t config);
  244. uint16_t get_gptimer_config(unsigned int timer_id);
  245. int get_gptimer_run(unsigned int timer_id);
  246. void set_gptimer_pulse_hi(unsigned int timer_id);
  247. void clear_gptimer_pulse_hi(unsigned int timer_id);
  248. void enable_gptimers(uint16_t mask);
  249. void disable_gptimers(uint16_t mask);
  250. void disable_gptimers_sync(uint16_t mask);
  251. uint16_t get_enabled_gptimers(void);
  252. uint32_t get_gptimer_status(unsigned int group);
  253. void set_gptimer_status(unsigned int group, uint32_t value);
  254. static inline void enable_gptimer(unsigned int timer_id)
  255. {
  256. enable_gptimers(1 << timer_id);
  257. }
  258. static inline void disable_gptimer(unsigned int timer_id)
  259. {
  260. disable_gptimers(1 << timer_id);
  261. }
  262. /*
  263. * All Blackfin system MMRs are padded to 32bits even if the register
  264. * itself is only 16bits. So use a helper macro to streamline this.
  265. */
  266. #define __BFP(m) u16 m; u16 __pad_##m
  267. /*
  268. * bfin timer registers layout
  269. */
  270. struct bfin_gptimer_regs {
  271. __BFP(config);
  272. u32 counter;
  273. u32 period;
  274. u32 width;
  275. #ifdef CONFIG_BF60x
  276. u32 delay;
  277. #endif
  278. };
  279. /*
  280. * bfin group timer registers layout
  281. */
  282. #ifndef CONFIG_BF60x
  283. struct bfin_gptimer_group_regs {
  284. __BFP(enable);
  285. __BFP(disable);
  286. u32 status;
  287. };
  288. #else
  289. struct bfin_gptimer_group_regs {
  290. __BFP(run);
  291. __BFP(enable);
  292. __BFP(disable);
  293. __BFP(stop_cfg);
  294. __BFP(stop_cfg_set);
  295. __BFP(stop_cfg_clr);
  296. __BFP(data_imsk);
  297. __BFP(stat_imsk);
  298. __BFP(tr_msk);
  299. __BFP(tr_ie);
  300. __BFP(data_ilat);
  301. __BFP(stat_ilat);
  302. __BFP(err_status);
  303. __BFP(bcast_per);
  304. __BFP(bcast_wid);
  305. __BFP(bcast_dly);
  306. };
  307. #endif
  308. #undef __BFP
  309. #endif