aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Miao <realmz6@gmail.com>2012-05-16 06:11:10 -0400
committerBob Liu <lliubbo@gmail.com>2012-05-21 02:54:20 -0400
commit2879bb30d788bb3841e2f1675ea7af5204eb171c (patch)
treea5d5eaca8faa37c95fda955c11a5c9d902bff7a5
parente578bbdeb8db3656eff428f097d6c8ed2f3718a5 (diff)
blackfin: bf60x: enable gptimer clock source
Signed-off-by: Steven Miao <realmz6@gmail.com> Signed-off-by: Bob Liu <lliubbo@gmail.com>
-rw-r--r--arch/blackfin/include/asm/gptimers.h104
-rw-r--r--arch/blackfin/kernel/gptimers.c83
-rw-r--r--arch/blackfin/kernel/time-ts.c27
3 files changed, 211 insertions, 3 deletions
diff --git a/arch/blackfin/include/asm/gptimers.h b/arch/blackfin/include/asm/gptimers.h
index 38bddcb190c8..381e3d621a4c 100644
--- a/arch/blackfin/include/asm/gptimers.h
+++ b/arch/blackfin/include/asm/gptimers.h
@@ -44,6 +44,13 @@
44# define TIMER_GROUP2 1 44# define TIMER_GROUP2 1
45#endif 45#endif
46/* 46/*
47 * BF609: 8 timers:
48 */
49#if defined(CONFIG_BF60x)
50# define MAX_BLACKFIN_GPTIMERS 8
51# define TIMER0_GROUP_REG TIMER_RUN
52#endif
53/*
47 * All others: 3 timers: 54 * All others: 3 timers:
48 */ 55 */
49#define TIMER_GROUP1 0 56#define TIMER_GROUP1 0
@@ -104,6 +111,72 @@
104# define FS2_TIMER_BIT TIMER1bit 111# define FS2_TIMER_BIT TIMER1bit
105#endif 112#endif
106 113
114#ifdef CONFIG_BF60x
115/*
116 * Timer Configuration Register Bits
117 */
118#define TIMER_EMU_RUN 0x8000
119#define TIMER_BPER_EN 0x4000
120#define TIMER_BWID_EN 0x2000
121#define TIMER_BDLY_EN 0x1000
122#define TIMER_OUT_DIS 0x0800
123#define TIMER_TIN_SEL 0x0400
124#define TIMER_CLK_SEL 0x0300
125#define TIMER_CLK_SCLK 0x0000
126#define TIMER_CLK_ALT_CLK0 0x0100
127#define TIMER_CLK_ALT_CLK1 0x0300
128#define TIMER_PULSE_HI 0x0080
129#define TIMER_SLAVE_TRIG 0x0040
130#define TIMER_IRQ_MODE 0x0030
131#define TIMER_IRQ_ACT_EDGE 0x0000
132#define TIMER_IRQ_DLY 0x0010
133#define TIMER_IRQ_WID_DLY 0x0020
134#define TIMER_IRQ_PER 0x0030
135#define TIMER_MODE 0x000f
136#define TIMER_MODE_WDOG_P 0x0008
137#define TIMER_MODE_WDOG_W 0x0009
138#define TIMER_MODE_PWM_CONT 0x000c
139#define TIMER_MODE_PWM 0x000d
140#define TIMER_MODE_WDTH 0x000a
141#define TIMER_MODE_WDTH_D 0x000b
142#define TIMER_MODE_EXT_CLK 0x000e
143#define TIMER_MODE_PININT 0x000f
144
145/*
146 * Timer Status Register Bits
147 */
148#define TIMER_STATUS_TIMIL0 0x0001
149#define TIMER_STATUS_TIMIL1 0x0002
150#define TIMER_STATUS_TIMIL2 0x0004
151#define TIMER_STATUS_TIMIL3 0x0008
152#define TIMER_STATUS_TIMIL4 0x0010
153#define TIMER_STATUS_TIMIL5 0x0020
154#define TIMER_STATUS_TIMIL6 0x0040
155#define TIMER_STATUS_TIMIL7 0x0080
156
157#define TIMER_STATUS_TOVF0 0x0001 /* timer 0 overflow error */
158#define TIMER_STATUS_TOVF1 0x0002
159#define TIMER_STATUS_TOVF2 0x0004
160#define TIMER_STATUS_TOVF3 0x0008
161#define TIMER_STATUS_TOVF4 0x0010
162#define TIMER_STATUS_TOVF5 0x0020
163#define TIMER_STATUS_TOVF6 0x0040
164#define TIMER_STATUS_TOVF7 0x0080
165
166/*
167 * Timer Slave Enable Status : write 1 to clear
168 */
169#define TIMER_STATUS_TRUN0 0x0001
170#define TIMER_STATUS_TRUN1 0x0002
171#define TIMER_STATUS_TRUN2 0x0004
172#define TIMER_STATUS_TRUN3 0x0008
173#define TIMER_STATUS_TRUN4 0x0010
174#define TIMER_STATUS_TRUN5 0x0020
175#define TIMER_STATUS_TRUN6 0x0040
176#define TIMER_STATUS_TRUN7 0x0080
177
178#else
179
107/* 180/*
108 * Timer Configuration Register Bits 181 * Timer Configuration Register Bits
109 */ 182 */
@@ -170,12 +243,18 @@
170#define TIMER_STATUS_TRUN10 0x4000 243#define TIMER_STATUS_TRUN10 0x4000
171#define TIMER_STATUS_TRUN11 0x8000 244#define TIMER_STATUS_TRUN11 0x8000
172 245
246#endif
247
173/* The actual gptimer API */ 248/* The actual gptimer API */
174 249
175void set_gptimer_pwidth(unsigned int timer_id, uint32_t width); 250void set_gptimer_pwidth(unsigned int timer_id, uint32_t width);
176uint32_t get_gptimer_pwidth(unsigned int timer_id); 251uint32_t get_gptimer_pwidth(unsigned int timer_id);
177void set_gptimer_period(unsigned int timer_id, uint32_t period); 252void set_gptimer_period(unsigned int timer_id, uint32_t period);
178uint32_t get_gptimer_period(unsigned int timer_id); 253uint32_t get_gptimer_period(unsigned int timer_id);
254#ifdef CONFIG_BF60x
255void set_gptimer_delay(unsigned int timer_id, uint32_t delay);
256uint32_t get_gptimer_delay(unsigned int timer_id);
257#endif
179uint32_t get_gptimer_count(unsigned int timer_id); 258uint32_t get_gptimer_count(unsigned int timer_id);
180int get_gptimer_intr(unsigned int timer_id); 259int get_gptimer_intr(unsigned int timer_id);
181void clear_gptimer_intr(unsigned int timer_id); 260void clear_gptimer_intr(unsigned int timer_id);
@@ -217,16 +296,41 @@ struct bfin_gptimer_regs {
217 u32 counter; 296 u32 counter;
218 u32 period; 297 u32 period;
219 u32 width; 298 u32 width;
299#ifdef CONFIG_BF60x
300 u32 delay;
301#endif
220}; 302};
221 303
222/* 304/*
223 * bfin group timer registers layout 305 * bfin group timer registers layout
224 */ 306 */
307#ifndef CONFIG_BF60x
225struct bfin_gptimer_group_regs { 308struct bfin_gptimer_group_regs {
226 __BFP(enable); 309 __BFP(enable);
227 __BFP(disable); 310 __BFP(disable);
228 u32 status; 311 u32 status;
229}; 312};
313#else
314struct bfin_gptimer_group_regs {
315 __BFP(run);
316 __BFP(enable);
317 __BFP(disable);
318 __BFP(stop_cfg);
319 __BFP(stop_cfg_set);
320 __BFP(stop_cfg_clr);
321 __BFP(data_imsk);
322 __BFP(stat_imsk);
323 __BFP(tr_msk);
324 __BFP(tr_ie);
325 __BFP(data_ilat);
326 __BFP(stat_ilat);
327 __BFP(err_status);
328 __BFP(bcast_per);
329 __BFP(bcast_wid);
330 __BFP(bcast_dly);
331
332};
333#endif
230 334
231#undef __BFP 335#undef __BFP
232 336
diff --git a/arch/blackfin/kernel/gptimers.c b/arch/blackfin/kernel/gptimers.c
index 06459f4bf43a..f7afe570f880 100644
--- a/arch/blackfin/kernel/gptimers.c
+++ b/arch/blackfin/kernel/gptimers.c
@@ -23,7 +23,11 @@
23 printk(KERN_DEBUG "%s:%s:%i: Assertion failed: " #expr "\n", __FILE__, __func__, __LINE__); 23 printk(KERN_DEBUG "%s:%s:%i: Assertion failed: " #expr "\n", __FILE__, __func__, __LINE__);
24#endif 24#endif
25 25
26#define BFIN_TIMER_NUM_GROUP (BFIN_TIMER_OCTET(MAX_BLACKFIN_GPTIMERS - 1) + 1) 26#ifndef CONFIG_BF60x
27# define BFIN_TIMER_NUM_GROUP (BFIN_TIMER_OCTET(MAX_BLACKFIN_GPTIMERS - 1) + 1)
28#else
29# define BFIN_TIMER_NUM_GROUP 1
30#endif
27 31
28static struct bfin_gptimer_regs * const timer_regs[MAX_BLACKFIN_GPTIMERS] = 32static struct bfin_gptimer_regs * const timer_regs[MAX_BLACKFIN_GPTIMERS] =
29{ 33{
@@ -158,6 +162,74 @@ uint32_t get_gptimer_count(unsigned int timer_id)
158} 162}
159EXPORT_SYMBOL(get_gptimer_count); 163EXPORT_SYMBOL(get_gptimer_count);
160 164
165#ifdef CONFIG_BF60x
166void set_gptimer_delay(unsigned int timer_id, uint32_t delay)
167{
168 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
169 bfin_write(&timer_regs[timer_id]->delay, delay);
170 SSYNC();
171}
172EXPORT_SYMBOL(set_gptimer_delay);
173
174uint32_t get_gptimer_delay(unsigned int timer_id)
175{
176 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
177 return bfin_read(&timer_regs[timer_id]->delay);
178}
179EXPORT_SYMBOL(get_gptimer_delay);
180#endif
181
182#ifdef CONFIG_BF60x
183int get_gptimer_intr(unsigned int timer_id)
184{
185 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
186 return !!(bfin_read(&group_regs[BFIN_TIMER_OCTET(timer_id)]->data_ilat) & timil_mask[timer_id]);
187}
188EXPORT_SYMBOL(get_gptimer_intr);
189
190void clear_gptimer_intr(unsigned int timer_id)
191{
192 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
193 bfin_write(&group_regs[BFIN_TIMER_OCTET(timer_id)]->data_ilat, timil_mask[timer_id]);
194}
195EXPORT_SYMBOL(clear_gptimer_intr);
196
197int get_gptimer_over(unsigned int timer_id)
198{
199 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
200 return !!(bfin_read(&group_regs[BFIN_TIMER_OCTET(timer_id)]->stat_ilat) & tovf_mask[timer_id]);
201}
202EXPORT_SYMBOL(get_gptimer_over);
203
204void clear_gptimer_over(unsigned int timer_id)
205{
206 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
207 bfin_write(&group_regs[BFIN_TIMER_OCTET(timer_id)]->stat_ilat, tovf_mask[timer_id]);
208}
209EXPORT_SYMBOL(clear_gptimer_over);
210
211int get_gptimer_run(unsigned int timer_id)
212{
213 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
214 return !!(bfin_read(&group_regs[BFIN_TIMER_OCTET(timer_id)]->run) & trun_mask[timer_id]);
215}
216EXPORT_SYMBOL(get_gptimer_run);
217
218uint32_t get_gptimer_status(unsigned int group)
219{
220 tassert(group < BFIN_TIMER_NUM_GROUP);
221 return bfin_read(&group_regs[group]->data_ilat);
222}
223EXPORT_SYMBOL(get_gptimer_status);
224
225void set_gptimer_status(unsigned int group, uint32_t value)
226{
227 tassert(group < BFIN_TIMER_NUM_GROUP);
228 bfin_write(&group_regs[group]->data_ilat, value);
229 SSYNC();
230}
231EXPORT_SYMBOL(set_gptimer_status);
232#else
161uint32_t get_gptimer_status(unsigned int group) 233uint32_t get_gptimer_status(unsigned int group)
162{ 234{
163 tassert(group < BFIN_TIMER_NUM_GROUP); 235 tassert(group < BFIN_TIMER_NUM_GROUP);
@@ -212,6 +284,7 @@ int get_gptimer_run(unsigned int timer_id)
212 return !!(read_gptimer_status(timer_id) & trun_mask[timer_id]); 284 return !!(read_gptimer_status(timer_id) & trun_mask[timer_id]);
213} 285}
214EXPORT_SYMBOL(get_gptimer_run); 286EXPORT_SYMBOL(get_gptimer_run);
287#endif
215 288
216void set_gptimer_config(unsigned int timer_id, uint16_t config) 289void set_gptimer_config(unsigned int timer_id, uint16_t config)
217{ 290{
@@ -231,6 +304,12 @@ EXPORT_SYMBOL(get_gptimer_config);
231void enable_gptimers(uint16_t mask) 304void enable_gptimers(uint16_t mask)
232{ 305{
233 int i; 306 int i;
307#ifdef CONFIG_BF60x
308 uint16_t imask;
309 imask = bfin_read16(TIMER_DATA_IMSK);
310 imask &= ~mask;
311 bfin_write16(TIMER_DATA_IMSK, imask);
312#endif
234 tassert((mask & ~BLACKFIN_GPTIMER_IDMASK) == 0); 313 tassert((mask & ~BLACKFIN_GPTIMER_IDMASK) == 0);
235 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i) { 314 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i) {
236 bfin_write(&group_regs[i]->enable, mask & 0xFF); 315 bfin_write(&group_regs[i]->enable, mask & 0xFF);
@@ -255,10 +334,12 @@ void disable_gptimers(uint16_t mask)
255{ 334{
256 int i; 335 int i;
257 _disable_gptimers(mask); 336 _disable_gptimers(mask);
337#ifndef CONFIG_BF60x
258 for (i = 0; i < MAX_BLACKFIN_GPTIMERS; ++i) 338 for (i = 0; i < MAX_BLACKFIN_GPTIMERS; ++i)
259 if (mask & (1 << i)) 339 if (mask & (1 << i))
260 bfin_write(&group_regs[BFIN_TIMER_OCTET(i)]->status, trun_mask[i]); 340 bfin_write(&group_regs[BFIN_TIMER_OCTET(i)]->status, trun_mask[i]);
261 SSYNC(); 341 SSYNC();
342#endif
262} 343}
263EXPORT_SYMBOL(disable_gptimers); 344EXPORT_SYMBOL(disable_gptimers);
264 345
diff --git a/arch/blackfin/kernel/time-ts.c b/arch/blackfin/kernel/time-ts.c
index d98f2d69b0c4..f608f02f29a3 100644
--- a/arch/blackfin/kernel/time-ts.c
+++ b/arch/blackfin/kernel/time-ts.c
@@ -66,8 +66,14 @@ void __init setup_gptimer0(void)
66{ 66{
67 disable_gptimers(TIMER0bit); 67 disable_gptimers(TIMER0bit);
68 68
69#ifdef CONFIG_BF60x
70 bfin_write16(TIMER_DATA_IMSK, 0);
71 set_gptimer_config(TIMER0_id, TIMER_OUT_DIS
72 | TIMER_MODE_PWM_CONT | TIMER_PULSE_HI | TIMER_IRQ_PER);
73#else
69 set_gptimer_config(TIMER0_id, \ 74 set_gptimer_config(TIMER0_id, \
70 TIMER_OUT_DIS | TIMER_PERIOD_CNT | TIMER_MODE_PWM); 75 TIMER_OUT_DIS | TIMER_PERIOD_CNT | TIMER_MODE_PWM);
76#endif
71 set_gptimer_period(TIMER0_id, -1); 77 set_gptimer_period(TIMER0_id, -1);
72 set_gptimer_pwidth(TIMER0_id, -2); 78 set_gptimer_pwidth(TIMER0_id, -2);
73 SSYNC(); 79 SSYNC();
@@ -135,9 +141,15 @@ static void bfin_gptmr0_set_mode(enum clock_event_mode mode,
135{ 141{
136 switch (mode) { 142 switch (mode) {
137 case CLOCK_EVT_MODE_PERIODIC: { 143 case CLOCK_EVT_MODE_PERIODIC: {
144#ifndef CONFIG_BF60x
138 set_gptimer_config(TIMER0_id, \ 145 set_gptimer_config(TIMER0_id, \
139 TIMER_OUT_DIS | TIMER_IRQ_ENA | \ 146 TIMER_OUT_DIS | TIMER_IRQ_ENA | \
140 TIMER_PERIOD_CNT | TIMER_MODE_PWM); 147 TIMER_PERIOD_CNT | TIMER_MODE_PWM);
148#else
149 set_gptimer_config(TIMER0_id, TIMER_OUT_DIS
150 | TIMER_MODE_PWM_CONT | TIMER_PULSE_HI | TIMER_IRQ_PER);
151#endif
152
141 set_gptimer_period(TIMER0_id, get_sclk() / HZ); 153 set_gptimer_period(TIMER0_id, get_sclk() / HZ);
142 set_gptimer_pwidth(TIMER0_id, get_sclk() / HZ - 1); 154 set_gptimer_pwidth(TIMER0_id, get_sclk() / HZ - 1);
143 enable_gptimers(TIMER0bit); 155 enable_gptimers(TIMER0bit);
@@ -145,8 +157,14 @@ static void bfin_gptmr0_set_mode(enum clock_event_mode mode,
145 } 157 }
146 case CLOCK_EVT_MODE_ONESHOT: 158 case CLOCK_EVT_MODE_ONESHOT:
147 disable_gptimers(TIMER0bit); 159 disable_gptimers(TIMER0bit);
160#ifndef CONFIG_BF60x
148 set_gptimer_config(TIMER0_id, \ 161 set_gptimer_config(TIMER0_id, \
149 TIMER_OUT_DIS | TIMER_IRQ_ENA | TIMER_MODE_PWM); 162 TIMER_OUT_DIS | TIMER_IRQ_ENA | TIMER_MODE_PWM);
163#else
164 set_gptimer_config(TIMER0_id, TIMER_OUT_DIS | TIMER_MODE_PWM
165 | TIMER_PULSE_HI | TIMER_IRQ_WID_DLY);
166#endif
167
150 set_gptimer_period(TIMER0_id, 0); 168 set_gptimer_period(TIMER0_id, 0);
151 break; 169 break;
152 case CLOCK_EVT_MODE_UNUSED: 170 case CLOCK_EVT_MODE_UNUSED:
@@ -160,7 +178,7 @@ static void bfin_gptmr0_set_mode(enum clock_event_mode mode,
160 178
161static void bfin_gptmr0_ack(void) 179static void bfin_gptmr0_ack(void)
162{ 180{
163 set_gptimer_status(TIMER_GROUP1, TIMER_STATUS_TIMIL0); 181 clear_gptimer_intr(TIMER0_id);
164} 182}
165 183
166static void __init bfin_gptmr0_init(void) 184static void __init bfin_gptmr0_init(void)
@@ -197,7 +215,7 @@ static struct clock_event_device clockevent_gptmr0 = {
197 .rating = 300, 215 .rating = 300,
198 .irq = IRQ_TIMER0, 216 .irq = IRQ_TIMER0,
199 .shift = 32, 217 .shift = 32,
200 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT, 218 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
201 .set_next_event = bfin_gptmr0_set_next_event, 219 .set_next_event = bfin_gptmr0_set_next_event,
202 .set_mode = bfin_gptmr0_set_mode, 220 .set_mode = bfin_gptmr0_set_mode,
203}; 221};
@@ -312,6 +330,11 @@ void bfin_coretmr_clockevent_init(void)
312#endif 330#endif
313 331
314 332
333#ifdef CONFIG_SMP
334 evt->broadcast = smp_timer_broadcast;
335#endif
336
337
315 evt->name = "bfin_core_timer"; 338 evt->name = "bfin_core_timer";
316 evt->rating = 350; 339 evt->rating = 350;
317 evt->irq = -1; 340 evt->irq = -1;