Skip to content

Commit bfd6d02

Browse files
author
Jon Hunter
committed
ARM: OMAP3+: Implement timer workaround for errata i103 and i767
Errata Titles: i103: Delay needed to read some GP timer, WD timer and sync timer registers after wakeup (OMAP3/4) i767: Delay needed to read some GP timer registers after wakeup (OMAP5) Description (i103/i767): If a General Purpose Timer (GPTimer) is in posted mode (TSICR [2].POSTED=1), due to internal resynchronizations, values read in TCRR, TCAR1 and TCAR2 registers right after the timer interface clock (L4) goes from stopped to active may not return the expected values. The most common event leading to this situation occurs upon wake up from idle. GPTimer non-posted synchronization mode is not impacted by this limitation. Workarounds: 1). Disable posted mode 2). Use static dependency between timer clock domain and MPUSS clock domain 3). Use no-idle mode when the timer is active Workarounds #2 and #3 are not pratical from a power standpoint and so workaround #1 has been implemented. Disabling posted mode adds some CPU overhead for configuring and reading the timers as the CPU has to wait for accesses to be re-synchronised within the timer. However, disabling posted mode guarantees correct operation. Please note that it is safe to use posted mode for timers if the counter (TCRR) and capture (TCARx) registers will never be read. An example of this is the clock-event system timer. This is used by the kernel to schedule events however, the timers counter is never read and capture registers are not used. Given that the kernel configures this timer often yet never reads the counter register it is safe to enable posted mode in this case. Hence, for the timer used for kernel clock-events, posted mode is enabled by overriding the errata for devices that are impacted by this defect. For drivers using the timers that do not read the counter or capture registers and wish to use posted mode, can override the errata and enable posted mode by making the following function calls. __omap_dm_timer_override_errata(timer, OMAP_TIMER_ERRATA_I103_I767); __omap_dm_timer_enable_posted(timer); Both dmtimers and watchdogs are impacted by this defect this patch only implements the workaround for the dmtimer. Currently the watchdog driver does not read the counter register and so no workaround is necessary. Posted mode will be disabled for all OMAP2+ devices (including AM33xx) using a GP timer as a clock-source timer to guarantee correct operation. This is not necessary for OMAP24xx devices but the default clock-source timer for OMAP24xx devices is the 32k-sync timer and not the GP timer and so should not have any impact. This should be re-visited for future devices if this errata is fixed. Confirmed with Vaibhav Hiremath that this bug also impacts AM33xx devices. Signed-off-by: Jon Hunter <[email protected]> Acked-by: Santosh Shilimkar <[email protected]>
1 parent 971d025 commit bfd6d02

File tree

3 files changed

+93
-11
lines changed

3 files changed

+93
-11
lines changed

arch/arm/mach-omap2/timer.c

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,24 @@ void __init omap_dmtimer_init(void)
222222
}
223223
}
224224

225+
/**
226+
* omap_dm_timer_get_errata - get errata flags for a timer
227+
*
228+
* Get the timer errata flags that are specific to the OMAP device being used.
229+
*/
230+
u32 __init omap_dm_timer_get_errata(void)
231+
{
232+
if (cpu_is_omap24xx())
233+
return 0;
234+
235+
return OMAP_TIMER_ERRATA_I103_I767;
236+
}
237+
225238
static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
226239
int gptimer_id,
227240
const char *fck_source,
228-
const char *property)
241+
const char *property,
242+
int posted)
229243
{
230244
char name[10]; /* 10 = sizeof("gptXX_Xck0") */
231245
const char *oh_name;
@@ -311,10 +325,15 @@ static int __init omap_dm_timer_init_one(struct omap_dm_timer *timer,
311325
}
312326
__omap_dm_timer_init_regs(timer);
313327
__omap_dm_timer_reset(timer, 1, 1);
314-
timer->posted = 1;
315328

316-
timer->rate = clk_get_rate(timer->fclk);
329+
if (posted)
330+
__omap_dm_timer_enable_posted(timer);
331+
332+
/* Check that the intended posted configuration matches the actual */
333+
if (posted != timer->posted)
334+
return -EINVAL;
317335

336+
timer->rate = clk_get_rate(timer->fclk);
318337
timer->reserved = 1;
319338

320339
return res;
@@ -326,7 +345,17 @@ static void __init omap2_gp_clockevent_init(int gptimer_id,
326345
{
327346
int res;
328347

329-
res = omap_dm_timer_init_one(&clkev, gptimer_id, fck_source, property);
348+
clkev.errata = omap_dm_timer_get_errata();
349+
350+
/*
351+
* For clock-event timers we never read the timer counter and
352+
* so we are not impacted by errata i103 and i767. Therefore,
353+
* we can safely ignore this errata for clock-event timers.
354+
*/
355+
__omap_dm_timer_override_errata(&clkev, OMAP_TIMER_ERRATA_I103_I767);
356+
357+
res = omap_dm_timer_init_one(&clkev, gptimer_id, fck_source, property,
358+
OMAP_TIMER_POSTED);
330359
BUG_ON(res);
331360

332361
omap2_gp_timer_irq.dev_id = &clkev;
@@ -360,7 +389,7 @@ static bool use_gptimer_clksrc;
360389
static cycle_t clocksource_read_cycles(struct clocksource *cs)
361390
{
362391
return (cycle_t)__omap_dm_timer_read_counter(&clksrc,
363-
OMAP_TIMER_POSTED);
392+
OMAP_TIMER_NONPOSTED);
364393
}
365394

366395
static struct clocksource clocksource_gpt = {
@@ -375,7 +404,7 @@ static u32 notrace dmtimer_read_sched_clock(void)
375404
{
376405
if (clksrc.reserved)
377406
return __omap_dm_timer_read_counter(&clksrc,
378-
OMAP_TIMER_POSTED);
407+
OMAP_TIMER_NONPOSTED);
379408

380409
return 0;
381410
}
@@ -453,12 +482,15 @@ static void __init omap2_gptimer_clocksource_init(int gptimer_id,
453482
{
454483
int res;
455484

456-
res = omap_dm_timer_init_one(&clksrc, gptimer_id, fck_source, NULL);
485+
clksrc.errata = omap_dm_timer_get_errata();
486+
487+
res = omap_dm_timer_init_one(&clksrc, gptimer_id, fck_source, NULL,
488+
OMAP_TIMER_NONPOSTED);
457489
BUG_ON(res);
458490

459491
__omap_dm_timer_load_start(&clksrc,
460492
OMAP_TIMER_CTRL_ST | OMAP_TIMER_CTRL_AR, 0,
461-
OMAP_TIMER_POSTED);
493+
OMAP_TIMER_NONPOSTED);
462494
setup_sched_clock(dmtimer_read_sched_clock, 32, clksrc.rate);
463495

464496
if (clocksource_register_hz(&clocksource_gpt, clksrc.rate))
@@ -696,6 +728,7 @@ static int __init omap_timer_init(struct omap_hwmod *oh, void *unused)
696728
if (timer_dev_attr)
697729
pdata->timer_capability = timer_dev_attr->timer_capability;
698730

731+
pdata->timer_errata = omap_dm_timer_get_errata();
699732
pdata->get_context_loss_count = omap_pm_get_dev_context_loss_count;
700733

701734
pdev = omap_device_build(name, id, oh, pdata, sizeof(*pdata),

arch/arm/plat-omap/dmtimer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ static void omap_dm_timer_reset(struct omap_dm_timer *timer)
128128
}
129129

130130
__omap_dm_timer_reset(timer, 0, 0);
131+
__omap_dm_timer_enable_posted(timer);
131132
omap_dm_timer_disable(timer);
132-
timer->posted = 1;
133133
}
134134

135135
int omap_dm_timer_prepare(struct omap_dm_timer *timer)
@@ -797,6 +797,7 @@ static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
797797
timer->capability |= OMAP_TIMER_SECURE;
798798
} else {
799799
timer->id = pdev->id;
800+
timer->errata = pdata->timer_errata;
800801
timer->capability = pdata->timer_capability;
801802
timer->reserved = omap_dm_timer_reserved_systimer(timer->id);
802803
timer->get_context_loss_count = pdata->get_context_loss_count;

arch/arm/plat-omap/include/plat/dmtimer.h

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@
6666
#define OMAP_TIMER_NEEDS_RESET 0x10000000
6767
#define OMAP_TIMER_HAS_DSP_IRQ 0x08000000
6868

69+
/*
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+
6979
struct omap_timer_capability_dev_attr {
7080
u32 timer_capability;
7181
};
@@ -97,6 +107,7 @@ struct timer_regs {
97107
struct dmtimer_platform_data {
98108
/* set_timer_src - Only used for OMAP1 devices */
99109
int (*set_timer_src)(struct platform_device *pdev, int source);
110+
u32 timer_errata;
100111
u32 timer_capability;
101112
int (*get_context_loss_count)(struct device *);
102113
};
@@ -273,6 +284,7 @@ struct omap_dm_timer {
273284
int ctx_loss_count;
274285
int revision;
275286
u32 capability;
287+
u32 errata;
276288
struct platform_device *pdev;
277289
struct list_head node;
278290
};
@@ -344,10 +356,46 @@ static inline void __omap_dm_timer_reset(struct omap_dm_timer *timer,
344356
l |= 1 << 2;
345357

346358
__raw_writel(l, timer->io_base + OMAP_TIMER_OCP_CFG_OFFSET);
359+
}
360+
361+
/*
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+
*/
371+
static 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;
347378

348-
/* Match hardware reset default of posted mode */
349379
__omap_dm_timer_write(timer, OMAP_TIMER_IF_CTRL_REG,
350-
OMAP_TIMER_CTRL_POSTED, 0);
380+
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+
*/
395+
static inline void __omap_dm_timer_override_errata(struct omap_dm_timer *timer,
396+
u32 errata)
397+
{
398+
timer->errata &= ~errata;
351399
}
352400

353401
static inline int __omap_dm_timer_set_source(struct clk *timer_fck,

0 commit comments

Comments
 (0)