blob: 4f318f1fd2d901214b5771c53d3e19854db971c6 [file] [log] [blame]
Mike Frysinger780431e2007-10-21 23:37:54 +08001/*
Mike Frysingerfee40112008-02-25 15:06:07 +08002 * gptimers.h - Blackfin General Purpose Timer structs/defines/prototypes
Mike Frysinger780431e2007-10-21 23:37:54 +08003 *
Mike Frysingerfee40112008-02-25 15:06:07 +08004 * Copyright (c) 2005-2008 Analog Devices Inc.
Mike Frysinger780431e2007-10-21 23:37:54 +08005 * Copyright (C) 2005 John DeHority
6 * Copyright (C) 2006 Hella Aglaia GmbH (awe@aglaia-gmbh.de)
7 *
Mike Frysingerfee40112008-02-25 15:06:07 +08008 * Licensed under the GPL-2.
Mike Frysinger780431e2007-10-21 23:37:54 +08009 */
10
11#ifndef _BLACKFIN_TIMERS_H_
12#define _BLACKFIN_TIMERS_H_
13
14#include <linux/types.h>
15#include <asm/blackfin.h>
16
17/*
18 * BF537/BF527: 8 timers:
19 */
20#if defined(BF527_FAMILY) || defined(BF537_FAMILY)
21# define MAX_BLACKFIN_GPTIMERS 8
22# define TIMER0_GROUP_REG TIMER_ENABLE
23#endif
24/*
25 * BF561: 12 timers:
26 */
27#if defined(CONFIG_BF561)
28# define MAX_BLACKFIN_GPTIMERS 12
29# define TIMER0_GROUP_REG TMRS8_ENABLE
30# define TIMER8_GROUP_REG TMRS4_ENABLE
31#endif
32/*
33 * All others: 3 timers:
34 */
35#if !defined(MAX_BLACKFIN_GPTIMERS)
36# define MAX_BLACKFIN_GPTIMERS 3
37# define TIMER0_GROUP_REG TIMER_ENABLE
38#endif
39
40#define BLACKFIN_GPTIMER_IDMASK ((1UL << MAX_BLACKFIN_GPTIMERS) - 1)
41#define BFIN_TIMER_OCTET(x) ((x) >> 3)
42
43/* used in masks for timer_enable() and timer_disable() */
44#define TIMER0bit 0x0001 /* 0001b */
45#define TIMER1bit 0x0002 /* 0010b */
46#define TIMER2bit 0x0004 /* 0100b */
47
48#if (MAX_BLACKFIN_GPTIMERS > 3)
49# define TIMER3bit 0x0008
50# define TIMER4bit 0x0010
51# define TIMER5bit 0x0020
52# define TIMER6bit 0x0040
53# define TIMER7bit 0x0080
54#endif
55
56#if (MAX_BLACKFIN_GPTIMERS > 8)
57# define TIMER8bit 0x0100
58# define TIMER9bit 0x0200
59# define TIMER10bit 0x0400
60# define TIMER11bit 0x0800
61#endif
62
63#define TIMER0_id 0
64#define TIMER1_id 1
65#define TIMER2_id 2
66
67#if (MAX_BLACKFIN_GPTIMERS > 3)
68# define TIMER3_id 3
69# define TIMER4_id 4
70# define TIMER5_id 5
71# define TIMER6_id 6
72# define TIMER7_id 7
73#endif
74
75#if (MAX_BLACKFIN_GPTIMERS > 8)
76# define TIMER8_id 8
77# define TIMER9_id 9
78# define TIMER10_id 10
79# define TIMER11_id 11
80#endif
81
82/* associated timers for ppi framesync: */
83
84#if defined(CONFIG_BF561)
85# define FS0_1_TIMER_ID TIMER8_id
86# define FS0_2_TIMER_ID TIMER9_id
87# define FS1_1_TIMER_ID TIMER10_id
88# define FS1_2_TIMER_ID TIMER11_id
89# define FS0_1_TIMER_BIT TIMER8bit
90# define FS0_2_TIMER_BIT TIMER9bit
91# define FS1_1_TIMER_BIT TIMER10bit
92# define FS1_2_TIMER_BIT TIMER11bit
93# undef FS1_TIMER_ID
94# undef FS2_TIMER_ID
95# undef FS1_TIMER_BIT
96# undef FS2_TIMER_BIT
97#else
98# define FS1_TIMER_ID TIMER0_id
99# define FS2_TIMER_ID TIMER1_id
100# define FS1_TIMER_BIT TIMER0bit
101# define FS2_TIMER_BIT TIMER1bit
102#endif
103
104/*
105 * Timer Configuration Register Bits
106 */
107#define TIMER_ERR 0xC000
108#define TIMER_ERR_OVFL 0x4000
109#define TIMER_ERR_PROG_PER 0x8000
110#define TIMER_ERR_PROG_PW 0xC000
111#define TIMER_EMU_RUN 0x0200
112#define TIMER_TOGGLE_HI 0x0100
113#define TIMER_CLK_SEL 0x0080
114#define TIMER_OUT_DIS 0x0040
115#define TIMER_TIN_SEL 0x0020
116#define TIMER_IRQ_ENA 0x0010
117#define TIMER_PERIOD_CNT 0x0008
118#define TIMER_PULSE_HI 0x0004
119#define TIMER_MODE 0x0003
120#define TIMER_MODE_PWM 0x0001
121#define TIMER_MODE_WDTH 0x0002
122#define TIMER_MODE_EXT_CLK 0x0003
123
124/*
125 * Timer Status Register Bits
126 */
127#define TIMER_STATUS_TIMIL0 0x0001
128#define TIMER_STATUS_TIMIL1 0x0002
129#define TIMER_STATUS_TIMIL2 0x0004
130#if (MAX_BLACKFIN_GPTIMERS > 3)
131# define TIMER_STATUS_TIMIL3 0x00000008
132# define TIMER_STATUS_TIMIL4 0x00010000
133# define TIMER_STATUS_TIMIL5 0x00020000
134# define TIMER_STATUS_TIMIL6 0x00040000
135# define TIMER_STATUS_TIMIL7 0x00080000
136# if (MAX_BLACKFIN_GPTIMERS > 8)
137# define TIMER_STATUS_TIMIL8 0x0001
138# define TIMER_STATUS_TIMIL9 0x0002
139# define TIMER_STATUS_TIMIL10 0x0004
140# define TIMER_STATUS_TIMIL11 0x0008
141# endif
142# define TIMER_STATUS_INTR 0x000F000F
143#else
144# define TIMER_STATUS_INTR 0x0007 /* any timer interrupt */
145#endif
146
147#define TIMER_STATUS_TOVF0 0x0010 /* timer 0 overflow error */
148#define TIMER_STATUS_TOVF1 0x0020
149#define TIMER_STATUS_TOVF2 0x0040
150#if (MAX_BLACKFIN_GPTIMERS > 3)
151# define TIMER_STATUS_TOVF3 0x00000080
152# define TIMER_STATUS_TOVF4 0x00100000
153# define TIMER_STATUS_TOVF5 0x00200000
154# define TIMER_STATUS_TOVF6 0x00400000
155# define TIMER_STATUS_TOVF7 0x00800000
156# if (MAX_BLACKFIN_GPTIMERS > 8)
157# define TIMER_STATUS_TOVF8 0x0010
158# define TIMER_STATUS_TOVF9 0x0020
159# define TIMER_STATUS_TOVF10 0x0040
160# define TIMER_STATUS_TOVF11 0x0080
161# endif
162# define TIMER_STATUS_OFLOW 0x00F000F0
163#else
164# define TIMER_STATUS_OFLOW 0x0070 /* any timer overflow */
165#endif
166
167/*
168 * Timer Slave Enable Status : write 1 to clear
169 */
170#define TIMER_STATUS_TRUN0 0x1000
171#define TIMER_STATUS_TRUN1 0x2000
172#define TIMER_STATUS_TRUN2 0x4000
173#if (MAX_BLACKFIN_GPTIMERS > 3)
174# define TIMER_STATUS_TRUN3 0x00008000
175# define TIMER_STATUS_TRUN4 0x10000000
176# define TIMER_STATUS_TRUN5 0x20000000
177# define TIMER_STATUS_TRUN6 0x40000000
178# define TIMER_STATUS_TRUN7 0x80000000
179# define TIMER_STATUS_TRUN 0xF000F000
180# if (MAX_BLACKFIN_GPTIMERS > 8)
181# define TIMER_STATUS_TRUN8 0x1000
182# define TIMER_STATUS_TRUN9 0x2000
183# define TIMER_STATUS_TRUN10 0x4000
184# define TIMER_STATUS_TRUN11 0x8000
185# endif
186#else
187# define TIMER_STATUS_TRUN 0x7000
188#endif
189
190/* The actual gptimer API */
191
192void set_gptimer_pwidth (int timer_id, uint32_t width);
193uint32_t get_gptimer_pwidth (int timer_id);
194void set_gptimer_period (int timer_id, uint32_t period);
195uint32_t get_gptimer_period (int timer_id);
196uint32_t get_gptimer_count (int timer_id);
197uint16_t get_gptimer_intr (int timer_id);
198void clear_gptimer_intr (int timer_id);
Mike Frysinger4ad1ec72007-10-29 18:02:09 +0800199uint16_t get_gptimer_over (int timer_id);
200void clear_gptimer_over (int timer_id);
Mike Frysinger780431e2007-10-21 23:37:54 +0800201void set_gptimer_config (int timer_id, uint16_t config);
202uint16_t get_gptimer_config (int timer_id);
203void set_gptimer_pulse_hi (int timer_id);
204void clear_gptimer_pulse_hi(int timer_id);
205void enable_gptimers (uint16_t mask);
206void disable_gptimers (uint16_t mask);
207uint16_t get_enabled_gptimers (void);
208uint32_t get_gptimer_status (int group);
209void set_gptimer_status (int group, uint32_t value);
210
211#endif