aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/blackfin/Kconfig10
-rw-r--r--arch/blackfin/Makefile15
-rw-r--r--arch/blackfin/kernel/Makefile1
-rw-r--r--arch/blackfin/kernel/gptimers.c250
-rw-r--r--include/asm-blackfin/bf5xx_timers.h209
-rw-r--r--include/asm-blackfin/gptimers.h210
6 files changed, 484 insertions, 211 deletions
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index 17830535099..7888551ed93 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -788,6 +788,16 @@ config LARGE_ALLOCS
788 a lot of RAM, and you need to able to allocate very large 788 a lot of RAM, and you need to able to allocate very large
789 contiguous chunks. If unsure, say N. 789 contiguous chunks. If unsure, say N.
790 790
791config BFIN_GPTIMERS
792 tristate "Enable Blackfin General Purpose Timers API"
793 default n
794 help
795 Enable support for the General Purpose Timers API. If you
796 are unsure, say N.
797
798 To compile this driver as a module, choose M here: the module
799 will be called gptimers.ko.
800
791config BFIN_DMA_5XX 801config BFIN_DMA_5XX
792 bool "Enable DMA Support" 802 bool "Enable DMA Support"
793 depends on (BF52x || BF53x || BF561 || BF54x) 803 depends on (BF52x || BF53x || BF561 || BF54x)
diff --git a/arch/blackfin/Makefile b/arch/blackfin/Makefile
index 4a208f30f5c..3c87291bcda 100644
--- a/arch/blackfin/Makefile
+++ b/arch/blackfin/Makefile
@@ -105,12 +105,23 @@ archclean:
105 $(Q)$(MAKE) $(clean)=$(boot) 105 $(Q)$(MAKE) $(clean)=$(boot)
106 106
107 107
108all: vmImage
109boot := arch/$(ARCH)/boot 108boot := arch/$(ARCH)/boot
110BOOT_TARGETS = vmImage 109BOOT_TARGETS = vmImage
111.PHONY: $(BOOT_TARGETS) 110PHONY += $(BOOT_TARGETS) install
111KBUILD_IMAGE := $(boot)/vmImage
112
113all: vmImage
114
112$(BOOT_TARGETS): vmlinux 115$(BOOT_TARGETS): vmlinux
113 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@ 116 $(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
117
118install:
119 $(Q)$(MAKE) $(build)=$(boot) BOOTIMAGE=$(KBUILD_IMAGE) install
120
114define archhelp 121define archhelp
115 echo '* vmImage - Kernel-only image for U-Boot (arch/$(ARCH)/boot/vmImage)' 122 echo '* vmImage - Kernel-only image for U-Boot (arch/$(ARCH)/boot/vmImage)'
123 echo ' install - Install kernel using'
124 echo ' (your) ~/bin/$(CROSS_COMPILE)installkernel or'
125 echo ' (distribution) PATH: $(CROSS_COMPILE)installkernel or'
126 echo ' install to $$(INSTALL_PATH)'
116endef 127endef
diff --git a/arch/blackfin/kernel/Makefile b/arch/blackfin/kernel/Makefile
index 8aeb6066b19..8a4cfb293b2 100644
--- a/arch/blackfin/kernel/Makefile
+++ b/arch/blackfin/kernel/Makefile
@@ -9,6 +9,7 @@ obj-y := \
9 sys_bfin.o time.o traps.o irqchip.o dma-mapping.o flat.o \ 9 sys_bfin.o time.o traps.o irqchip.o dma-mapping.o flat.o \
10 fixed_code.o cplbinit.o cacheinit.o reboot.o bfin_gpio.o 10 fixed_code.o cplbinit.o cacheinit.o reboot.o bfin_gpio.o
11 11
12obj-$(CONFIG_BFIN_GPTIMERS) += gptimers.o
12obj-$(CONFIG_MODULES) += module.o 13obj-$(CONFIG_MODULES) += module.o
13obj-$(CONFIG_BFIN_DMA_5XX) += bfin_dma_5xx.o 14obj-$(CONFIG_BFIN_DMA_5XX) += bfin_dma_5xx.o
14obj-$(CONFIG_DUAL_CORE_TEST_MODULE) += dualcore_test.o 15obj-$(CONFIG_DUAL_CORE_TEST_MODULE) += dualcore_test.o
diff --git a/arch/blackfin/kernel/gptimers.c b/arch/blackfin/kernel/gptimers.c
new file mode 100644
index 00000000000..cb7ba9bfc79
--- /dev/null
+++ b/arch/blackfin/kernel/gptimers.c
@@ -0,0 +1,250 @@
1/*
2 * bfin_gptimers.c - derived from bf53x_timers.c
3 * Driver for General Purpose Timer functions on the Blackfin processor
4 *
5 * Copyright (C) 2005 John DeHority
6 * Copyright (C) 2006 Hella Aglaia GmbH (awe@aglaia-gmbh.de)
7 *
8 * Licensed under the GPLv2.
9 */
10
11#include <linux/kernel.h>
12#include <linux/module.h>
13
14#include <asm/io.h>
15#include <asm/blackfin.h>
16#include <asm/gptimers.h>
17
18#ifdef DEBUG
19# define tassert(expr)
20#else
21# define tassert(expr) \
22 if (!(expr)) \
23 printk(KERN_DEBUG "%s:%s:%i: Assertion failed: " #expr "\n", \
24 __FILE__, __func__, __LINE__);
25#endif
26
27#define BFIN_TIMER_NUM_GROUP (BFIN_TIMER_OCTET(MAX_BLACKFIN_GPTIMERS - 1) + 1)
28
29typedef struct {
30 uint16_t config;
31 uint16_t __pad;
32 uint32_t counter;
33 uint32_t period;
34 uint32_t width;
35} GPTIMER_timer_regs;
36
37typedef struct {
38 uint16_t enable;
39 uint16_t __pad0;
40 uint16_t disable;
41 uint16_t __pad1;
42 uint32_t status;
43} GPTIMER_group_regs;
44
45static volatile GPTIMER_timer_regs *const timer_regs[MAX_BLACKFIN_GPTIMERS] =
46{
47 (GPTIMER_timer_regs *)TIMER0_CONFIG,
48 (GPTIMER_timer_regs *)TIMER1_CONFIG,
49 (GPTIMER_timer_regs *)TIMER2_CONFIG,
50#if (MAX_BLACKFIN_GPTIMERS > 3)
51 (GPTIMER_timer_regs *)TIMER3_CONFIG,
52 (GPTIMER_timer_regs *)TIMER4_CONFIG,
53 (GPTIMER_timer_regs *)TIMER5_CONFIG,
54 (GPTIMER_timer_regs *)TIMER6_CONFIG,
55 (GPTIMER_timer_regs *)TIMER7_CONFIG,
56#endif
57#if (MAX_BLACKFIN_GPTIMERS > 8)
58 (GPTIMER_timer_regs *)TIMER8_CONFIG,
59 (GPTIMER_timer_regs *)TIMER9_CONFIG,
60 (GPTIMER_timer_regs *)TIMER10_CONFIG,
61 (GPTIMER_timer_regs *)TIMER11_CONFIG,
62#endif
63};
64
65static volatile GPTIMER_group_regs *const group_regs[BFIN_TIMER_NUM_GROUP] =
66{
67 (GPTIMER_group_regs *)TIMER0_GROUP_REG,
68#if (MAX_BLACKFIN_GPTIMERS > 8)
69 (GPTIMER_group_regs *)TIMER8_GROUP_REG,
70#endif
71};
72
73static uint32_t const dis_mask[MAX_BLACKFIN_GPTIMERS] =
74{
75 TIMER_STATUS_TRUN0,
76 TIMER_STATUS_TRUN1,
77 TIMER_STATUS_TRUN2,
78#if (MAX_BLACKFIN_GPTIMERS > 3)
79 TIMER_STATUS_TRUN3,
80 TIMER_STATUS_TRUN4,
81 TIMER_STATUS_TRUN5,
82 TIMER_STATUS_TRUN6,
83 TIMER_STATUS_TRUN7,
84#endif
85#if (MAX_BLACKFIN_GPTIMERS > 8)
86 TIMER_STATUS_TRUN8,
87 TIMER_STATUS_TRUN9,
88 TIMER_STATUS_TRUN10,
89 TIMER_STATUS_TRUN11,
90#endif
91};
92
93static uint32_t const irq_mask[MAX_BLACKFIN_GPTIMERS] =
94{
95 TIMER_STATUS_TIMIL0,
96 TIMER_STATUS_TIMIL1,
97 TIMER_STATUS_TIMIL2,
98#if (MAX_BLACKFIN_GPTIMERS > 3)
99 TIMER_STATUS_TIMIL3,
100 TIMER_STATUS_TIMIL4,
101 TIMER_STATUS_TIMIL5,
102 TIMER_STATUS_TIMIL6,
103 TIMER_STATUS_TIMIL7,
104#endif
105#if (MAX_BLACKFIN_GPTIMERS > 8)
106 TIMER_STATUS_TIMIL8,
107 TIMER_STATUS_TIMIL9,
108 TIMER_STATUS_TIMIL10,
109 TIMER_STATUS_TIMIL11,
110#endif
111};
112
113void set_gptimer_pwidth(int timer_id, uint32_t value)
114{
115 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
116 timer_regs[timer_id]->width = value;
117 SSYNC();
118}
119EXPORT_SYMBOL(set_gptimer_pwidth);
120
121uint32_t get_gptimer_pwidth(int timer_id)
122{
123 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
124 return timer_regs[timer_id]->width;
125}
126EXPORT_SYMBOL(get_gptimer_pwidth);
127
128void set_gptimer_period(int timer_id, uint32_t period)
129{
130 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
131 timer_regs[timer_id]->period = period;
132 SSYNC();
133}
134EXPORT_SYMBOL(set_gptimer_period);
135
136uint32_t get_gptimer_period(int timer_id)
137{
138 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
139 return timer_regs[timer_id]->period;
140}
141EXPORT_SYMBOL(get_gptimer_period);
142
143uint32_t get_gptimer_count(int timer_id)
144{
145 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
146 return timer_regs[timer_id]->counter;
147}
148EXPORT_SYMBOL(get_gptimer_count);
149
150uint32_t get_gptimer_status(int group)
151{
152 tassert(group < BFIN_TIMER_NUM_GROUP);
153 return group_regs[group]->status;
154}
155EXPORT_SYMBOL(get_gptimer_status);
156
157void set_gptimer_status(int group, uint32_t value)
158{
159 tassert(group < BFIN_TIMER_NUM_GROUP);
160 group_regs[group]->status = value;
161 SSYNC();
162}
163EXPORT_SYMBOL(set_gptimer_status);
164
165uint16_t get_gptimer_intr(int timer_id)
166{
167 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
168 return (group_regs[BFIN_TIMER_OCTET(timer_id)]->status & irq_mask[timer_id]) ? 1 : 0;
169}
170EXPORT_SYMBOL(get_gptimer_intr);
171
172void clear_gptimer_intr(int timer_id)
173{
174 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
175 group_regs[BFIN_TIMER_OCTET(timer_id)]->status = irq_mask[timer_id];
176}
177EXPORT_SYMBOL(clear_gptimer_intr);
178
179void set_gptimer_config(int timer_id, uint16_t config)
180{
181 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
182 timer_regs[timer_id]->config = config;
183 SSYNC();
184}
185EXPORT_SYMBOL(set_gptimer_config);
186
187uint16_t get_gptimer_config(int timer_id)
188{
189 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
190 return timer_regs[timer_id]->config;
191}
192EXPORT_SYMBOL(get_gptimer_config);
193
194void enable_gptimers(uint16_t mask)
195{
196 int i;
197 tassert((mask & ~BLACKFIN_GPTIMER_IDMASK) == 0);
198 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i) {
199 group_regs[i]->enable = mask & 0xFF;
200 mask >>= 8;
201 }
202 SSYNC();
203}
204EXPORT_SYMBOL(enable_gptimers);
205
206void disable_gptimers(uint16_t mask)
207{
208 int i;
209 uint16_t m = mask;
210 tassert((mask & ~BLACKFIN_GPTIMER_IDMASK) == 0);
211 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i) {
212 group_regs[i]->disable = m & 0xFF;
213 m >>= 8;
214 }
215 for (i = 0; i < MAX_BLACKFIN_GPTIMERS; ++i)
216 if (mask & (1 << i))
217 group_regs[BFIN_TIMER_OCTET(i)]->status |= dis_mask[i];
218 SSYNC();
219}
220EXPORT_SYMBOL(disable_gptimers);
221
222void set_gptimer_pulse_hi(int timer_id)
223{
224 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
225 timer_regs[timer_id]->config |= TIMER_PULSE_HI;
226 SSYNC();
227}
228EXPORT_SYMBOL(set_gptimer_pulse_hi);
229
230void clear_gptimer_pulse_hi(int timer_id)
231{
232 tassert(timer_id < MAX_BLACKFIN_GPTIMERS);
233 timer_regs[timer_id]->config &= ~TIMER_PULSE_HI;
234 SSYNC();
235}
236EXPORT_SYMBOL(clear_gptimer_pulse_hi);
237
238uint16_t get_enabled_gptimers(void)
239{
240 int i;
241 uint16_t result = 0;
242 for (i = 0; i < BFIN_TIMER_NUM_GROUP; ++i)
243 result |= (group_regs[i]->enable << (i << 3));
244 return result;
245}
246EXPORT_SYMBOL(get_enabled_gptimers);
247
248MODULE_AUTHOR("Axel Weiss (awe@aglaia-gmbh.de)");
249MODULE_DESCRIPTION("Blackfin General Purpose Timers API");
250MODULE_LICENSE("GPL");
diff --git a/include/asm-blackfin/bf5xx_timers.h b/include/asm-blackfin/bf5xx_timers.h
deleted file mode 100644
index 8e8246f32fe..00000000000
--- a/include/asm-blackfin/bf5xx_timers.h
+++ /dev/null
@@ -1,209 +0,0 @@
1/*
2 * include/asm/bf5xx_timers.h
3 *
4 * This file contains the major Data structures and constants
5 * used for General Purpose Timer Implementation in BF5xx
6 *
7 * Copyright (C) 2005 John DeHority
8 * Copyright (C) 2006 Hella Aglaia GmbH (awe@aglaia-gmbh.de)
9 *
10 */
11
12#ifndef _BLACKFIN_TIMERS_H_
13#define _BLACKFIN_TIMERS_H_
14
15#undef MAX_BLACKFIN_GPTIMERS
16/*
17 * BF537: 8 timers:
18 */
19#if defined(BF527_FAMILY) || defined(BF537_FAMILY)
20# define MAX_BLACKFIN_GPTIMERS 8
21# define TIMER0_GROUP_REG TIMER_ENABLE
22#endif
23/*
24 * BF561: 12 timers:
25 */
26#if defined(CONFIG_BF561)
27# define MAX_BLACKFIN_GPTIMERS 12
28# define TIMER0_GROUP_REG TMRS8_ENABLE
29# define TIMER8_GROUP_REG TMRS4_ENABLE
30#endif
31/*
32 * All others: 3 timers:
33 */
34#if !defined(MAX_BLACKFIN_GPTIMERS)
35# define MAX_BLACKFIN_GPTIMERS 3
36# define TIMER0_GROUP_REG TIMER_ENABLE
37#endif
38
39#define BLACKFIN_GPTIMER_IDMASK ((1UL << MAX_BLACKFIN_GPTIMERS) - 1)
40#define BFIN_TIMER_OCTET(x) ((x) >> 3)
41
42/* used in masks for timer_enable() and timer_disable() */
43#define TIMER0bit 0x0001 /* 0001b */
44#define TIMER1bit 0x0002 /* 0010b */
45#define TIMER2bit 0x0004 /* 0100b */
46
47#if (MAX_BLACKFIN_GPTIMERS > 3)
48# define TIMER3bit 0x0008
49# define TIMER4bit 0x0010
50# define TIMER5bit 0x0020
51# define TIMER6bit 0x0040
52# define TIMER7bit 0x0080
53#endif
54
55#if (MAX_BLACKFIN_GPTIMERS > 8)
56# define TIMER8bit 0x0100
57# define TIMER9bit 0x0200
58# define TIMER10bit 0x0400
59# define TIMER11bit 0x0800
60#endif
61
62#define TIMER0_id 0
63#define TIMER1_id 1
64#define TIMER2_id 2
65
66#if (MAX_BLACKFIN_GPTIMERS > 3)
67# define TIMER3_id 3
68# define TIMER4_id 4
69# define TIMER5_id 5
70# define TIMER6_id 6
71# define TIMER7_id 7
72#endif
73
74#if (MAX_BLACKFIN_GPTIMERS > 8)
75# define TIMER8_id 8
76# define TIMER9_id 9
77# define TIMER10_id 10
78# define TIMER11_id 11
79#endif
80
81/* associated timers for ppi framesync: */
82
83#if defined(CONFIG_BF561)
84# define FS0_1_TIMER_ID TIMER8_id
85# define FS0_2_TIMER_ID TIMER9_id
86# define FS1_1_TIMER_ID TIMER10_id
87# define FS1_2_TIMER_ID TIMER11_id
88# define FS0_1_TIMER_BIT TIMER8bit
89# define FS0_2_TIMER_BIT TIMER9bit
90# define FS1_1_TIMER_BIT TIMER10bit
91# define FS1_2_TIMER_BIT TIMER11bit
92# undef FS1_TIMER_ID
93# undef FS2_TIMER_ID
94# undef FS1_TIMER_BIT
95# undef FS2_TIMER_BIT
96#else
97# define FS1_TIMER_ID TIMER0_id
98# define FS2_TIMER_ID TIMER1_id
99# define FS1_TIMER_BIT TIMER0bit
100# define FS2_TIMER_BIT TIMER1bit
101#endif
102
103/*
104** Timer Configuration Register Bits
105*/
106#define TIMER_ERR 0xC000
107#define TIMER_ERR_OVFL 0x4000
108#define TIMER_ERR_PROG_PER 0x8000
109#define TIMER_ERR_PROG_PW 0xC000
110#define TIMER_EMU_RUN 0x0200
111#define TIMER_TOGGLE_HI 0x0100
112#define TIMER_CLK_SEL 0x0080
113#define TIMER_OUT_DIS 0x0040
114#define TIMER_TIN_SEL 0x0020
115#define TIMER_IRQ_ENA 0x0010
116#define TIMER_PERIOD_CNT 0x0008
117#define TIMER_PULSE_HI 0x0004
118#define TIMER_MODE 0x0003
119#define TIMER_MODE_PWM 0x0001
120#define TIMER_MODE_WDTH 0x0002
121#define TIMER_MODE_EXT_CLK 0x0003
122
123/*
124** Timer Status Register Bits
125*/
126#define TIMER_STATUS_TIMIL0 0x0001
127#define TIMER_STATUS_TIMIL1 0x0002
128#define TIMER_STATUS_TIMIL2 0x0004
129#if (MAX_BLACKFIN_GPTIMERS > 3)
130# define TIMER_STATUS_TIMIL3 0x00000008
131# define TIMER_STATUS_TIMIL4 0x00010000
132# define TIMER_STATUS_TIMIL5 0x00020000
133# define TIMER_STATUS_TIMIL6 0x00040000
134# define TIMER_STATUS_TIMIL7 0x00080000
135# if (MAX_BLACKFIN_GPTIMERS > 8)
136# define TIMER_STATUS_TIMIL8 0x0001
137# define TIMER_STATUS_TIMIL9 0x0002
138# define TIMER_STATUS_TIMIL10 0x0004
139# define TIMER_STATUS_TIMIL11 0x0008
140# endif
141# define TIMER_STATUS_INTR 0x000F000F
142#else
143# define TIMER_STATUS_INTR 0x0007 /* any timer interrupt */
144#endif
145
146#define TIMER_STATUS_TOVF0 0x0010 /* timer 0 overflow error */
147#define TIMER_STATUS_TOVF1 0x0020
148#define TIMER_STATUS_TOVF2 0x0040
149#if (MAX_BLACKFIN_GPTIMERS > 3)
150# define TIMER_STATUS_TOVF3 0x00000080
151# define TIMER_STATUS_TOVF4 0x00100000
152# define TIMER_STATUS_TOVF5 0x00200000
153# define TIMER_STATUS_TOVF6 0x00400000
154# define TIMER_STATUS_TOVF7 0x00800000
155# if (MAX_BLACKFIN_GPTIMERS > 8)
156# define TIMER_STATUS_TOVF8 0x0010
157# define TIMER_STATUS_TOVF9 0x0020
158# define TIMER_STATUS_TOVF10 0x0040
159# define TIMER_STATUS_TOVF11 0x0080
160# endif
161# define TIMER_STATUS_OFLOW 0x00F000F0
162#else
163# define TIMER_STATUS_OFLOW 0x0070 /* any timer overflow */
164#endif
165
166/*
167** Timer Slave Enable Status : write 1 to clear
168*/
169#define TIMER_STATUS_TRUN0 0x1000
170#define TIMER_STATUS_TRUN1 0x2000
171#define TIMER_STATUS_TRUN2 0x4000
172#if (MAX_BLACKFIN_GPTIMERS > 3)
173# define TIMER_STATUS_TRUN3 0x00008000
174# define TIMER_STATUS_TRUN4 0x10000000
175# define TIMER_STATUS_TRUN5 0x20000000
176# define TIMER_STATUS_TRUN6 0x40000000
177# define TIMER_STATUS_TRUN7 0x80000000
178# define TIMER_STATUS_TRUN 0xF000F000
179# if (MAX_BLACKFIN_GPTIMERS > 8)
180# define TIMER_STATUS_TRUN8 0x1000
181# define TIMER_STATUS_TRUN9 0x2000
182# define TIMER_STATUS_TRUN10 0x4000
183# define TIMER_STATUS_TRUN11 0x8000
184# endif
185#else
186# define TIMER_STATUS_TRUN 0x7000
187#endif
188
189/*******************************************************************************
190* GP_TIMER API's
191*******************************************************************************/
192
193void set_gptimer_pwidth (int timer_id, int width);
194int get_gptimer_pwidth (int timer_id);
195void set_gptimer_period (int timer_id, int period);
196int get_gptimer_period (int timer_id);
197int get_gptimer_count (int timer_id);
198short get_gptimer_intr (int timer_id);
199void set_gptimer_config (int timer_id, short config);
200short get_gptimer_config (int timer_id);
201void set_gptimer_pulse_hi (int timer_id);
202void clear_gptimer_pulse_hi(int timer_id);
203void enable_gptimers (short mask);
204void disable_gptimers (short mask);
205short get_enabled_timers (void);
206int get_gptimer_status (int octet);
207void set_gptimer_status (int octet, int value);
208
209#endif
diff --git a/include/asm-blackfin/gptimers.h b/include/asm-blackfin/gptimers.h
new file mode 100644
index 00000000000..c97ab03e43a
--- /dev/null
+++ b/include/asm-blackfin/gptimers.h
@@ -0,0 +1,210 @@
1/*
2 * include/asm/bf5xx_timers.h
3 *
4 * This file contains the major Data structures and constants
5 * used for General Purpose Timer Implementation in BF5xx
6 *
7 * Copyright (C) 2005 John DeHority
8 * Copyright (C) 2006 Hella Aglaia GmbH (awe@aglaia-gmbh.de)
9 *
10 */
11
12#ifndef _BLACKFIN_TIMERS_H_
13#define _BLACKFIN_TIMERS_H_
14
15#include <linux/types.h>
16#include <asm/blackfin.h>
17
18/*
19 * BF537/BF527: 8 timers:
20 */
21#if defined(BF527_FAMILY) || defined(BF537_FAMILY)
22# define MAX_BLACKFIN_GPTIMERS 8
23# define TIMER0_GROUP_REG TIMER_ENABLE
24#endif
25/*
26 * BF561: 12 timers:
27 */
28#if defined(CONFIG_BF561)
29# define MAX_BLACKFIN_GPTIMERS 12
30# define TIMER0_GROUP_REG TMRS8_ENABLE
31# define TIMER8_GROUP_REG TMRS4_ENABLE
32#endif
33/*
34 * All others: 3 timers:
35 */
36#if !defined(MAX_BLACKFIN_GPTIMERS)
37# define MAX_BLACKFIN_GPTIMERS 3
38# define TIMER0_GROUP_REG TIMER_ENABLE
39#endif
40
41#define BLACKFIN_GPTIMER_IDMASK ((1UL << MAX_BLACKFIN_GPTIMERS) - 1)
42#define BFIN_TIMER_OCTET(x) ((x) >> 3)
43
44/* used in masks for timer_enable() and timer_disable() */
45#define TIMER0bit 0x0001 /* 0001b */
46#define TIMER1bit 0x0002 /* 0010b */
47#define TIMER2bit 0x0004 /* 0100b */
48
49#if (MAX_BLACKFIN_GPTIMERS > 3)
50# define TIMER3bit 0x0008
51# define TIMER4bit 0x0010
52# define TIMER5bit 0x0020
53# define TIMER6bit 0x0040
54# define TIMER7bit 0x0080
55#endif
56
57#if (MAX_BLACKFIN_GPTIMERS > 8)
58# define TIMER8bit 0x0100
59# define TIMER9bit 0x0200
60# define TIMER10bit 0x0400
61# define TIMER11bit 0x0800
62#endif
63
64#define TIMER0_id 0
65#define TIMER1_id 1
66#define TIMER2_id 2
67
68#if (MAX_BLACKFIN_GPTIMERS > 3)
69# define TIMER3_id 3
70# define TIMER4_id 4
71# define TIMER5_id 5
72# define TIMER6_id 6
73# define TIMER7_id 7
74#endif
75
76#if (MAX_BLACKFIN_GPTIMERS > 8)
77# define TIMER8_id 8
78# define TIMER9_id 9
79# define TIMER10_id 10
80# define TIMER11_id 11
81#endif
82
83/* associated timers for ppi framesync: */
84
85#if defined(CONFIG_BF561)
86# define FS0_1_TIMER_ID TIMER8_id
87# define FS0_2_TIMER_ID TIMER9_id
88# define FS1_1_TIMER_ID TIMER10_id
89# define FS1_2_TIMER_ID TIMER11_id
90# define FS0_1_TIMER_BIT TIMER8bit
91# define FS0_2_TIMER_BIT TIMER9bit
92# define FS1_1_TIMER_BIT TIMER10bit
93# define FS1_2_TIMER_BIT TIMER11bit
94# undef FS1_TIMER_ID
95# undef FS2_TIMER_ID
96# undef FS1_TIMER_BIT
97# undef FS2_TIMER_BIT
98#else
99# define FS1_TIMER_ID TIMER0_id
100# define FS2_TIMER_ID TIMER1_id
101# define FS1_TIMER_BIT TIMER0bit
102# define FS2_TIMER_BIT TIMER1bit
103#endif
104
105/*
106 * Timer Configuration Register Bits
107 */
108#define TIMER_ERR 0xC000
109#define TIMER_ERR_OVFL 0x4000
110#define TIMER_ERR_PROG_PER 0x8000
111#define TIMER_ERR_PROG_PW 0xC000
112#define TIMER_EMU_RUN 0x0200
113#define TIMER_TOGGLE_HI 0x0100
114#define TIMER_CLK_SEL 0x0080
115#define TIMER_OUT_DIS 0x0040
116#define TIMER_TIN_SEL 0x0020
117#define TIMER_IRQ_ENA 0x0010
118#define TIMER_PERIOD_CNT 0x0008
119#define TIMER_PULSE_HI 0x0004
120#define TIMER_MODE 0x0003
121#define TIMER_MODE_PWM 0x0001
122#define TIMER_MODE_WDTH 0x0002
123#define TIMER_MODE_EXT_CLK 0x0003
124
125/*
126 * Timer Status Register Bits
127 */
128#define TIMER_STATUS_TIMIL0 0x0001
129#define TIMER_STATUS_TIMIL1 0x0002
130#define TIMER_STATUS_TIMIL2 0x0004
131#if (MAX_BLACKFIN_GPTIMERS > 3)
132# define TIMER_STATUS_TIMIL3 0x00000008
133# define TIMER_STATUS_TIMIL4 0x00010000
134# define TIMER_STATUS_TIMIL5 0x00020000
135# define TIMER_STATUS_TIMIL6 0x00040000
136# define TIMER_STATUS_TIMIL7 0x00080000
137# if (MAX_BLACKFIN_GPTIMERS > 8)
138# define TIMER_STATUS_TIMIL8 0x0001
139# define TIMER_STATUS_TIMIL9 0x0002
140# define TIMER_STATUS_TIMIL10 0x0004
141# define TIMER_STATUS_TIMIL11 0x0008
142# endif
143# define TIMER_STATUS_INTR 0x000F000F
144#else
145# define TIMER_STATUS_INTR 0x0007 /* any timer interrupt */
146#endif
147
148#define TIMER_STATUS_TOVF0 0x0010 /* timer 0 overflow error */
149#define TIMER_STATUS_TOVF1 0x0020
150#define TIMER_STATUS_TOVF2 0x0040
151#if (MAX_BLACKFIN_GPTIMERS > 3)
152# define TIMER_STATUS_TOVF3 0x00000080
153# define TIMER_STATUS_TOVF4 0x00100000
154# define TIMER_STATUS_TOVF5 0x00200000
155# define TIMER_STATUS_TOVF6 0x00400000
156# define TIMER_STATUS_TOVF7 0x00800000
157# if (MAX_BLACKFIN_GPTIMERS > 8)
158# define TIMER_STATUS_TOVF8 0x0010
159# define TIMER_STATUS_TOVF9 0x0020
160# define TIMER_STATUS_TOVF10 0x0040
161# define TIMER_STATUS_TOVF11 0x0080
162# endif
163# define TIMER_STATUS_OFLOW 0x00F000F0
164#else
165# define TIMER_STATUS_OFLOW 0x0070 /* any timer overflow */
166#endif
167
168/*
169 * Timer Slave Enable Status : write 1 to clear
170 */
171#define TIMER_STATUS_TRUN0 0x1000
172#define TIMER_STATUS_TRUN1 0x2000
173#define TIMER_STATUS_TRUN2 0x4000
174#if (MAX_BLACKFIN_GPTIMERS > 3)
175# define TIMER_STATUS_TRUN3 0x00008000
176# define TIMER_STATUS_TRUN4 0x10000000
177# define TIMER_STATUS_TRUN5 0x20000000
178# define TIMER_STATUS_TRUN6 0x40000000
179# define TIMER_STATUS_TRUN7 0x80000000
180# define TIMER_STATUS_TRUN 0xF000F000
181# if (MAX_BLACKFIN_GPTIMERS > 8)
182# define TIMER_STATUS_TRUN8 0x1000
183# define TIMER_STATUS_TRUN9 0x2000
184# define TIMER_STATUS_TRUN10 0x4000
185# define TIMER_STATUS_TRUN11 0x8000
186# endif
187#else
188# define TIMER_STATUS_TRUN 0x7000
189#endif
190
191/* The actual gptimer API */
192
193void set_gptimer_pwidth (int timer_id, uint32_t width);
194uint32_t get_gptimer_pwidth (int timer_id);
195void set_gptimer_period (int timer_id, uint32_t period);
196uint32_t get_gptimer_period (int timer_id);
197uint32_t get_gptimer_count (int timer_id);
198uint16_t get_gptimer_intr (int timer_id);
199void clear_gptimer_intr (int timer_id);
200void set_gptimer_config (int timer_id, uint16_t config);
201uint16_t get_gptimer_config (int timer_id);
202void set_gptimer_pulse_hi (int timer_id);
203void clear_gptimer_pulse_hi(int timer_id);
204void enable_gptimers (uint16_t mask);
205void disable_gptimers (uint16_t mask);
206uint16_t get_enabled_gptimers (void);
207uint32_t get_gptimer_status (int group);
208void set_gptimer_status (int group, uint32_t value);
209
210#endif