blob: ac16f1e9d0e089ed94119b4abf53f531f6f46560 [file] [log] [blame]
Russell Kinga09e64f2008-08-05 16:14:15 +01001/*
Tarun Kanti DebBarmac345c8b2011-09-20 17:00:18 +05302 * arch/arm/plat-omap/include/plat/dmtimer.h
Russell Kinga09e64f2008-08-05 16:14:15 +01003 *
4 * OMAP Dual-Mode Timers
5 *
Thara Gopinatheddb1262011-02-23 00:14:04 -07006 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
7 * Tarun Kanti DebBarma <tarun.kanti@ti.com>
8 * Thara Gopinath <thara@ti.com>
9 *
10 * Platform device conversion and hwmod support.
11 *
Russell Kinga09e64f2008-08-05 16:14:15 +010012 * Copyright (C) 2005 Nokia Corporation
13 * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com>
14 * PWM and clock framwork support by Timo Teras.
15 *
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 2 of the License, or (at your
19 * option) any later version.
20 *
21 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
24 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * You should have received a copy of the GNU General Public License along
31 * with this program; if not, write to the Free Software Foundation, Inc.,
32 * 675 Mass Ave, Cambridge, MA 02139, USA.
33 */
34
Tony Lindgrencaf64f22011-03-29 15:54:48 -070035#include <linux/clk.h>
36#include <linux/delay.h>
Paul Walmsleya7cd4b082011-07-09 18:00:25 -060037#include <linux/io.h>
Tarun Kanti DebBarma97933d62011-09-20 17:00:17 +053038#include <linux/platform_device.h>
Tony Lindgrencaf64f22011-03-29 15:54:48 -070039
Russell Kinga09e64f2008-08-05 16:14:15 +010040#ifndef __ASM_ARCH_DMTIMER_H
41#define __ASM_ARCH_DMTIMER_H
42
43/* clock sources */
44#define OMAP_TIMER_SRC_SYS_CLK 0x00
45#define OMAP_TIMER_SRC_32_KHZ 0x01
46#define OMAP_TIMER_SRC_EXT_CLK 0x02
47
48/* timer interrupt enable bits */
49#define OMAP_TIMER_INT_CAPTURE (1 << 2)
50#define OMAP_TIMER_INT_OVERFLOW (1 << 1)
51#define OMAP_TIMER_INT_MATCH (1 << 0)
52
53/* trigger types */
54#define OMAP_TIMER_TRIGGER_NONE 0x00
55#define OMAP_TIMER_TRIGGER_OVERFLOW 0x01
56#define OMAP_TIMER_TRIGGER_OVERFLOW_AND_COMPARE 0x02
57
Jon Hunter971d0252012-09-27 11:49:45 -050058/* posted mode types */
59#define OMAP_TIMER_NONPOSTED 0x00
60#define OMAP_TIMER_POSTED 0x01
61
Tarun Kanti DebBarmac345c8b2011-09-20 17:00:18 +053062/* timer capabilities used in hwmod database */
63#define OMAP_TIMER_SECURE 0x80000000
64#define OMAP_TIMER_ALWON 0x40000000
65#define OMAP_TIMER_HAS_PWM 0x20000000
Jon Hunter66159752012-06-05 12:34:57 -050066#define OMAP_TIMER_NEEDS_RESET 0x10000000
Jon Hunter5c3e4ec2012-09-23 17:28:27 -060067#define OMAP_TIMER_HAS_DSP_IRQ 0x08000000
Tarun Kanti DebBarmac345c8b2011-09-20 17:00:18 +053068
Jon Hunterbfd6d022012-09-27 12:47:43 -050069/*
70 * timer errata flags
71 *
72 * Errata i103/i767 impacts all OMAP3/4/5 devices including AM33xx. This
73 * errata prevents us from using posted mode on these devices, unless the
74 * timer counter register is never read. For more details please refer to
75 * the OMAP3/4/5 errata documents.
76 */
77#define OMAP_TIMER_ERRATA_I103_I767 0x80000000
78
Tarun Kanti DebBarmac345c8b2011-09-20 17:00:18 +053079struct omap_timer_capability_dev_attr {
80 u32 timer_capability;
81};
82
Russell Kinga09e64f2008-08-05 16:14:15 +010083struct omap_dm_timer;
Russell Kinga09e64f2008-08-05 16:14:15 +010084
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +053085struct timer_regs {
86 u32 tidr;
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +053087 u32 tistat;
88 u32 tisr;
89 u32 tier;
90 u32 twer;
91 u32 tclr;
92 u32 tcrr;
93 u32 tldr;
94 u32 ttrg;
95 u32 twps;
96 u32 tmar;
97 u32 tcar1;
98 u32 tsicr;
99 u32 tcar2;
100 u32 tpir;
101 u32 tnir;
102 u32 tcvr;
103 u32 tocr;
104 u32 towr;
105};
106
Tarun Kanti DebBarma97933d62011-09-20 17:00:17 +0530107struct dmtimer_platform_data {
Jon Hunter2b2d3522012-06-05 12:34:59 -0500108 /* set_timer_src - Only used for OMAP1 devices */
Tarun Kanti DebBarma97933d62011-09-20 17:00:17 +0530109 int (*set_timer_src)(struct platform_device *pdev, int source);
Jon Hunterbfd6d022012-09-27 12:47:43 -0500110 u32 timer_errata;
Jon Hunterd1c16912012-06-05 12:34:52 -0500111 u32 timer_capability;
Tony Lindgren6e740f92012-10-29 15:20:45 -0700112 int (*get_context_loss_count)(struct device *);
Tarun Kanti DebBarma97933d62011-09-20 17:00:17 +0530113};
114
Jon Hunterb7b4ff72012-06-05 12:34:51 -0500115int omap_dm_timer_reserve_systimer(int id);
Russell Kinga09e64f2008-08-05 16:14:15 +0100116struct omap_dm_timer *omap_dm_timer_request(void);
117struct omap_dm_timer *omap_dm_timer_request_specific(int timer_id);
Jon Hunter373fe0b2012-09-06 15:28:00 -0500118struct omap_dm_timer *omap_dm_timer_request_by_cap(u32 cap);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530119int omap_dm_timer_free(struct omap_dm_timer *timer);
Russell Kinga09e64f2008-08-05 16:14:15 +0100120void omap_dm_timer_enable(struct omap_dm_timer *timer);
121void omap_dm_timer_disable(struct omap_dm_timer *timer);
122
123int omap_dm_timer_get_irq(struct omap_dm_timer *timer);
124
125u32 omap_dm_timer_modify_idlect_mask(u32 inputmask);
126struct clk *omap_dm_timer_get_fclk(struct omap_dm_timer *timer);
127
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530128int omap_dm_timer_trigger(struct omap_dm_timer *timer);
129int omap_dm_timer_start(struct omap_dm_timer *timer);
130int omap_dm_timer_stop(struct omap_dm_timer *timer);
Russell Kinga09e64f2008-08-05 16:14:15 +0100131
Paul Walmsleyf2480762009-04-23 21:11:10 -0600132int omap_dm_timer_set_source(struct omap_dm_timer *timer, int source);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530133int omap_dm_timer_set_load(struct omap_dm_timer *timer, int autoreload, unsigned int value);
134int omap_dm_timer_set_load_start(struct omap_dm_timer *timer, int autoreload, unsigned int value);
135int omap_dm_timer_set_match(struct omap_dm_timer *timer, int enable, unsigned int match);
136int omap_dm_timer_set_pwm(struct omap_dm_timer *timer, int def_on, int toggle, int trigger);
137int omap_dm_timer_set_prescaler(struct omap_dm_timer *timer, int prescaler);
Russell Kinga09e64f2008-08-05 16:14:15 +0100138
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530139int omap_dm_timer_set_int_enable(struct omap_dm_timer *timer, unsigned int value);
Russell Kinga09e64f2008-08-05 16:14:15 +0100140
141unsigned int omap_dm_timer_read_status(struct omap_dm_timer *timer);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530142int omap_dm_timer_write_status(struct omap_dm_timer *timer, unsigned int value);
Russell Kinga09e64f2008-08-05 16:14:15 +0100143unsigned int omap_dm_timer_read_counter(struct omap_dm_timer *timer);
Tarun Kanti DebBarmaab4eb8b2011-09-20 17:00:26 +0530144int omap_dm_timer_write_counter(struct omap_dm_timer *timer, unsigned int value);
Russell Kinga09e64f2008-08-05 16:14:15 +0100145
146int omap_dm_timers_active(void);
147
Tony Lindgrenec974892011-03-29 15:54:48 -0700148/*
149 * Do not use the defines below, they are not needed. They should be only
150 * used by dmtimer.c and sys_timer related code.
151 */
152
Tony Lindgrenee17f112011-09-16 15:44:20 -0700153/*
154 * The interrupt registers are different between v1 and v2 ip.
155 * These registers are offsets from timer->iobase.
156 */
157#define OMAP_TIMER_ID_OFFSET 0x00
158#define OMAP_TIMER_OCP_CFG_OFFSET 0x10
159
160#define OMAP_TIMER_V1_SYS_STAT_OFFSET 0x14
161#define OMAP_TIMER_V1_STAT_OFFSET 0x18
162#define OMAP_TIMER_V1_INT_EN_OFFSET 0x1c
163
164#define OMAP_TIMER_V2_IRQSTATUS_RAW 0x24
165#define OMAP_TIMER_V2_IRQSTATUS 0x28
166#define OMAP_TIMER_V2_IRQENABLE_SET 0x2c
167#define OMAP_TIMER_V2_IRQENABLE_CLR 0x30
168
169/*
170 * The functional registers have a different base on v1 and v2 ip.
171 * These registers are offsets from timer->func_base. The func_base
172 * is samae as io_base for v1 and io_base + 0x14 for v2 ip.
173 *
174 */
175#define OMAP_TIMER_V2_FUNC_OFFSET 0x14
176
Tony Lindgrenec974892011-03-29 15:54:48 -0700177#define _OMAP_TIMER_WAKEUP_EN_OFFSET 0x20
178#define _OMAP_TIMER_CTRL_OFFSET 0x24
179#define OMAP_TIMER_CTRL_GPOCFG (1 << 14)
180#define OMAP_TIMER_CTRL_CAPTMODE (1 << 13)
181#define OMAP_TIMER_CTRL_PT (1 << 12)
182#define OMAP_TIMER_CTRL_TCM_LOWTOHIGH (0x1 << 8)
183#define OMAP_TIMER_CTRL_TCM_HIGHTOLOW (0x2 << 8)
184#define OMAP_TIMER_CTRL_TCM_BOTHEDGES (0x3 << 8)
185#define OMAP_TIMER_CTRL_SCPWM (1 << 7)
186#define OMAP_TIMER_CTRL_CE (1 << 6) /* compare enable */
187#define OMAP_TIMER_CTRL_PRE (1 << 5) /* prescaler enable */
188#define OMAP_TIMER_CTRL_PTV_SHIFT 2 /* prescaler value shift */
189#define OMAP_TIMER_CTRL_POSTED (1 << 2)
190#define OMAP_TIMER_CTRL_AR (1 << 1) /* auto-reload enable */
191#define OMAP_TIMER_CTRL_ST (1 << 0) /* start timer */
192#define _OMAP_TIMER_COUNTER_OFFSET 0x28
193#define _OMAP_TIMER_LOAD_OFFSET 0x2c
194#define _OMAP_TIMER_TRIGGER_OFFSET 0x30
195#define _OMAP_TIMER_WRITE_PEND_OFFSET 0x34
196#define WP_NONE 0 /* no write pending bit */
197#define WP_TCLR (1 << 0)
198#define WP_TCRR (1 << 1)
199#define WP_TLDR (1 << 2)
200#define WP_TTGR (1 << 3)
201#define WP_TMAR (1 << 4)
202#define WP_TPIR (1 << 5)
203#define WP_TNIR (1 << 6)
204#define WP_TCVR (1 << 7)
205#define WP_TOCR (1 << 8)
206#define WP_TOWR (1 << 9)
207#define _OMAP_TIMER_MATCH_OFFSET 0x38
208#define _OMAP_TIMER_CAPTURE_OFFSET 0x3c
209#define _OMAP_TIMER_IF_CTRL_OFFSET 0x40
210#define _OMAP_TIMER_CAPTURE2_OFFSET 0x44 /* TCAR2, 34xx only */
211#define _OMAP_TIMER_TICK_POS_OFFSET 0x48 /* TPIR, 34xx only */
212#define _OMAP_TIMER_TICK_NEG_OFFSET 0x4c /* TNIR, 34xx only */
213#define _OMAP_TIMER_TICK_COUNT_OFFSET 0x50 /* TCVR, 34xx only */
214#define _OMAP_TIMER_TICK_INT_MASK_SET_OFFSET 0x54 /* TOCR, 34xx only */
215#define _OMAP_TIMER_TICK_INT_MASK_COUNT_OFFSET 0x58 /* TOWR, 34xx only */
216
217/* register offsets with the write pending bit encoded */
218#define WPSHIFT 16
219
Tony Lindgrenec974892011-03-29 15:54:48 -0700220#define OMAP_TIMER_WAKEUP_EN_REG (_OMAP_TIMER_WAKEUP_EN_OFFSET \
221 | (WP_NONE << WPSHIFT))
222
223#define OMAP_TIMER_CTRL_REG (_OMAP_TIMER_CTRL_OFFSET \
224 | (WP_TCLR << WPSHIFT))
225
226#define OMAP_TIMER_COUNTER_REG (_OMAP_TIMER_COUNTER_OFFSET \
227 | (WP_TCRR << WPSHIFT))
228
229#define OMAP_TIMER_LOAD_REG (_OMAP_TIMER_LOAD_OFFSET \
230 | (WP_TLDR << WPSHIFT))
231
232#define OMAP_TIMER_TRIGGER_REG (_OMAP_TIMER_TRIGGER_OFFSET \
233 | (WP_TTGR << WPSHIFT))
234
235#define OMAP_TIMER_WRITE_PEND_REG (_OMAP_TIMER_WRITE_PEND_OFFSET \
236 | (WP_NONE << WPSHIFT))
237
238#define OMAP_TIMER_MATCH_REG (_OMAP_TIMER_MATCH_OFFSET \
239 | (WP_TMAR << WPSHIFT))
240
241#define OMAP_TIMER_CAPTURE_REG (_OMAP_TIMER_CAPTURE_OFFSET \
242 | (WP_NONE << WPSHIFT))
243
244#define OMAP_TIMER_IF_CTRL_REG (_OMAP_TIMER_IF_CTRL_OFFSET \
245 | (WP_NONE << WPSHIFT))
246
247#define OMAP_TIMER_CAPTURE2_REG (_OMAP_TIMER_CAPTURE2_OFFSET \
248 | (WP_NONE << WPSHIFT))
249
250#define OMAP_TIMER_TICK_POS_REG (_OMAP_TIMER_TICK_POS_OFFSET \
251 | (WP_TPIR << WPSHIFT))
252
253#define OMAP_TIMER_TICK_NEG_REG (_OMAP_TIMER_TICK_NEG_OFFSET \
254 | (WP_TNIR << WPSHIFT))
255
256#define OMAP_TIMER_TICK_COUNT_REG (_OMAP_TIMER_TICK_COUNT_OFFSET \
257 | (WP_TCVR << WPSHIFT))
258
259#define OMAP_TIMER_TICK_INT_MASK_SET_REG \
260 (_OMAP_TIMER_TICK_INT_MASK_SET_OFFSET | (WP_TOCR << WPSHIFT))
261
262#define OMAP_TIMER_TICK_INT_MASK_COUNT_REG \
263 (_OMAP_TIMER_TICK_INT_MASK_COUNT_OFFSET | (WP_TOWR << WPSHIFT))
264
265struct omap_dm_timer {
266 unsigned long phys_base;
Tarun Kanti DebBarmadf284722011-09-20 17:00:19 +0530267 int id;
Tony Lindgrenec974892011-03-29 15:54:48 -0700268 int irq;
Tarun Kanti DebBarmaf1bbbb12012-05-07 23:55:30 -0600269 struct clk *fclk;
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530270
Tony Lindgrenee17f112011-09-16 15:44:20 -0700271 void __iomem *io_base;
272 void __iomem *sys_stat; /* TISTAT timer status */
273 void __iomem *irq_stat; /* TISR/IRQSTATUS interrupt status */
274 void __iomem *irq_ena; /* irq enable */
275 void __iomem *irq_dis; /* irq disable, only on v2 ip */
276 void __iomem *pend; /* write pending */
277 void __iomem *func_base; /* function register base */
278
Tony Lindgrenaa561882011-03-29 15:54:48 -0700279 unsigned long rate;
Tony Lindgrenec974892011-03-29 15:54:48 -0700280 unsigned reserved:1;
Tony Lindgrenec974892011-03-29 15:54:48 -0700281 unsigned posted:1;
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530282 struct timer_regs context;
Tony Lindgren6e740f92012-10-29 15:20:45 -0700283 int (*get_context_loss_count)(struct device *);
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530284 int ctx_loss_count;
285 int revision;
Jon Hunterd1c16912012-06-05 12:34:52 -0500286 u32 capability;
Jon Hunterbfd6d022012-09-27 12:47:43 -0500287 u32 errata;
Tarun Kanti DebBarma97933d62011-09-20 17:00:17 +0530288 struct platform_device *pdev;
Tarun Kanti DebBarmadf284722011-09-20 17:00:19 +0530289 struct list_head node;
Tony Lindgrenec974892011-03-29 15:54:48 -0700290};
Russell Kinga09e64f2008-08-05 16:14:15 +0100291
Tarun Kanti DebBarma3392cdd2011-09-20 17:00:20 +0530292int omap_dm_timer_prepare(struct omap_dm_timer *timer);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700293
Tony Lindgrenee17f112011-09-16 15:44:20 -0700294static inline u32 __omap_dm_timer_read(struct omap_dm_timer *timer, u32 reg,
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700295 int posted)
296{
297 if (posted)
Tony Lindgrenee17f112011-09-16 15:44:20 -0700298 while (__raw_readl(timer->pend) & (reg >> WPSHIFT))
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700299 cpu_relax();
300
Tony Lindgrenee17f112011-09-16 15:44:20 -0700301 return __raw_readl(timer->func_base + (reg & 0xff));
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700302}
303
Tony Lindgrenee17f112011-09-16 15:44:20 -0700304static inline void __omap_dm_timer_write(struct omap_dm_timer *timer,
305 u32 reg, u32 val, int posted)
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700306{
307 if (posted)
Tony Lindgrenee17f112011-09-16 15:44:20 -0700308 while (__raw_readl(timer->pend) & (reg >> WPSHIFT))
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700309 cpu_relax();
310
Tony Lindgrenee17f112011-09-16 15:44:20 -0700311 __raw_writel(val, timer->func_base + (reg & 0xff));
312}
313
314static inline void __omap_dm_timer_init_regs(struct omap_dm_timer *timer)
315{
316 u32 tidr;
317
318 /* Assume v1 ip if bits [31:16] are zero */
319 tidr = __raw_readl(timer->io_base);
320 if (!(tidr >> 16)) {
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530321 timer->revision = 1;
Tony Lindgrenee17f112011-09-16 15:44:20 -0700322 timer->sys_stat = timer->io_base +
323 OMAP_TIMER_V1_SYS_STAT_OFFSET;
324 timer->irq_stat = timer->io_base + OMAP_TIMER_V1_STAT_OFFSET;
325 timer->irq_ena = timer->io_base + OMAP_TIMER_V1_INT_EN_OFFSET;
Paul Walmsleya7022d62012-04-13 06:34:28 -0600326 timer->irq_dis = NULL;
Tony Lindgrenee17f112011-09-16 15:44:20 -0700327 timer->pend = timer->io_base + _OMAP_TIMER_WRITE_PEND_OFFSET;
328 timer->func_base = timer->io_base;
329 } else {
Tarun Kanti DebBarmab4811132011-09-20 17:00:24 +0530330 timer->revision = 2;
Paul Walmsleya7022d62012-04-13 06:34:28 -0600331 timer->sys_stat = NULL;
Tony Lindgrenee17f112011-09-16 15:44:20 -0700332 timer->irq_stat = timer->io_base + OMAP_TIMER_V2_IRQSTATUS;
333 timer->irq_ena = timer->io_base + OMAP_TIMER_V2_IRQENABLE_SET;
334 timer->irq_dis = timer->io_base + OMAP_TIMER_V2_IRQENABLE_CLR;
335 timer->pend = timer->io_base +
336 _OMAP_TIMER_WRITE_PEND_OFFSET +
337 OMAP_TIMER_V2_FUNC_OFFSET;
338 timer->func_base = timer->io_base + OMAP_TIMER_V2_FUNC_OFFSET;
339 }
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700340}
341
342/* Assumes the source clock has been set by caller */
Tony Lindgrenee17f112011-09-16 15:44:20 -0700343static inline void __omap_dm_timer_reset(struct omap_dm_timer *timer,
344 int autoidle, int wakeup)
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700345{
346 u32 l;
347
Tony Lindgrenee17f112011-09-16 15:44:20 -0700348 l = __raw_readl(timer->io_base + OMAP_TIMER_OCP_CFG_OFFSET);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700349 l |= 0x02 << 3; /* Set to smart-idle mode */
350 l |= 0x2 << 8; /* Set clock activity to perserve f-clock on idle */
351
352 if (autoidle)
353 l |= 0x1 << 0;
354
355 if (wakeup)
356 l |= 1 << 2;
357
Tony Lindgrenee17f112011-09-16 15:44:20 -0700358 __raw_writel(l, timer->io_base + OMAP_TIMER_OCP_CFG_OFFSET);
Jon Hunterbfd6d022012-09-27 12:47:43 -0500359}
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700360
Jon Hunterbfd6d022012-09-27 12:47:43 -0500361/*
362 * __omap_dm_timer_enable_posted - enables write posted mode
363 * @timer: pointer to timer instance handle
364 *
365 * Enables the write posted mode for the timer. When posted mode is enabled
366 * writes to certain timer registers are immediately acknowledged by the
367 * internal bus and hence prevents stalling the CPU waiting for the write to
368 * complete. Enabling this feature can improve performance for writing to the
369 * timer registers.
370 */
371static inline void __omap_dm_timer_enable_posted(struct omap_dm_timer *timer)
372{
373 if (timer->posted)
374 return;
375
376 if (timer->errata & OMAP_TIMER_ERRATA_I103_I767)
377 return;
378
Tony Lindgrenee17f112011-09-16 15:44:20 -0700379 __omap_dm_timer_write(timer, OMAP_TIMER_IF_CTRL_REG,
Jon Hunterbfd6d022012-09-27 12:47:43 -0500380 OMAP_TIMER_CTRL_POSTED, 0);
381 timer->context.tsicr = OMAP_TIMER_CTRL_POSTED;
382 timer->posted = OMAP_TIMER_POSTED;
383}
384
385/**
386 * __omap_dm_timer_override_errata - override errata flags for a timer
387 * @timer: pointer to timer handle
388 * @errata: errata flags to be ignored
389 *
390 * For a given timer, override a timer errata by clearing the flags
391 * specified by the errata argument. A specific erratum should only be
392 * overridden for a timer if the timer is used in such a way the erratum
393 * has no impact.
394 */
395static inline void __omap_dm_timer_override_errata(struct omap_dm_timer *timer,
396 u32 errata)
397{
398 timer->errata &= ~errata;
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700399}
400
401static inline int __omap_dm_timer_set_source(struct clk *timer_fck,
402 struct clk *parent)
403{
404 int ret;
405
406 clk_disable(timer_fck);
407 ret = clk_set_parent(timer_fck, parent);
408 clk_enable(timer_fck);
409
410 /*
411 * When the functional clock disappears, too quick writes seem
412 * to cause an abort. XXX Is this still necessary?
413 */
414 __delay(300000);
415
416 return ret;
417}
418
Tony Lindgrenee17f112011-09-16 15:44:20 -0700419static inline void __omap_dm_timer_stop(struct omap_dm_timer *timer,
420 int posted, unsigned long rate)
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700421{
422 u32 l;
423
Tony Lindgrenee17f112011-09-16 15:44:20 -0700424 l = __omap_dm_timer_read(timer, OMAP_TIMER_CTRL_REG, posted);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700425 if (l & OMAP_TIMER_CTRL_ST) {
426 l &= ~0x1;
Tony Lindgrenee17f112011-09-16 15:44:20 -0700427 __omap_dm_timer_write(timer, OMAP_TIMER_CTRL_REG, l, posted);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700428#ifdef CONFIG_ARCH_OMAP2PLUS
429 /* Readback to make sure write has completed */
Tony Lindgrenee17f112011-09-16 15:44:20 -0700430 __omap_dm_timer_read(timer, OMAP_TIMER_CTRL_REG, posted);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700431 /*
432 * Wait for functional clock period x 3.5 to make sure that
433 * timer is stopped
434 */
435 udelay(3500000 / rate + 1);
436#endif
437 }
438
439 /* Ack possibly pending interrupt */
Tony Lindgrenee17f112011-09-16 15:44:20 -0700440 __raw_writel(OMAP_TIMER_INT_OVERFLOW, timer->irq_stat);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700441}
442
Tony Lindgrenee17f112011-09-16 15:44:20 -0700443static inline void __omap_dm_timer_load_start(struct omap_dm_timer *timer,
444 u32 ctrl, unsigned int load,
445 int posted)
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700446{
Tony Lindgrenee17f112011-09-16 15:44:20 -0700447 __omap_dm_timer_write(timer, OMAP_TIMER_COUNTER_REG, load, posted);
448 __omap_dm_timer_write(timer, OMAP_TIMER_CTRL_REG, ctrl, posted);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700449}
450
Tony Lindgrenee17f112011-09-16 15:44:20 -0700451static inline void __omap_dm_timer_int_enable(struct omap_dm_timer *timer,
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700452 unsigned int value)
453{
Tony Lindgrenee17f112011-09-16 15:44:20 -0700454 __raw_writel(value, timer->irq_ena);
455 __omap_dm_timer_write(timer, OMAP_TIMER_WAKEUP_EN_REG, value, 0);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700456}
457
Tony Lindgrenee17f112011-09-16 15:44:20 -0700458static inline unsigned int
459__omap_dm_timer_read_counter(struct omap_dm_timer *timer, int posted)
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700460{
Tony Lindgrenee17f112011-09-16 15:44:20 -0700461 return __omap_dm_timer_read(timer, OMAP_TIMER_COUNTER_REG, posted);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700462}
463
Tony Lindgrenee17f112011-09-16 15:44:20 -0700464static inline void __omap_dm_timer_write_status(struct omap_dm_timer *timer,
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700465 unsigned int value)
466{
Tony Lindgrenee17f112011-09-16 15:44:20 -0700467 __raw_writel(value, timer->irq_stat);
Tony Lindgrencaf64f22011-03-29 15:54:48 -0700468}
469
Russell Kinga09e64f2008-08-05 16:14:15 +0100470#endif /* __ASM_ARCH_DMTIMER_H */