Skip to content

Commit

Permalink
ARM: OMAP3+: Implement timer workaround for errata i103 and i767
Browse files Browse the repository at this point in the history
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 <jon-hunter@ti.com>
Acked-by: Santosh Shilimkar <santosh.shilimkar@ti.com>

Change-Id: Id10648050492d8c91ea22093127584f02ec3655b
  • Loading branch information
Jon Hunter authored and Quarx2k committed Sep 25, 2013
1 parent 6364eea commit 4962044
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 16 deletions.
15 changes: 15 additions & 0 deletions arch/arm/mach-omap2/dmtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@

static u8 __initdata system_timer_id;

/**
* omap_dm_timer_get_errata - get errata flags for a timer
*
* Get the timer errata flags that are specific to the OMAP device being used.
*/
static u32 __init omap_dm_timer_get_errata(void)
{
if (cpu_is_omap24xx())
return 0;

return OMAP_TIMER_ERRATA_I103_I767;
}

/**
* omap2_dm_timer_set_src - change the timer input clock source
* @pdev: timer platform device pointer
Expand Down Expand Up @@ -161,6 +174,7 @@ static int __init omap_timer_init(struct omap_hwmod *oh, void *unused)
goto err_free_mem;
}
pdata->loses_context = pwrdm_can_ever_lose_context(pwrdm);
pdata->timer_errata = omap_dm_timer_get_errata();

od = omap_device_build(name, id, oh, pdata, sizeof(*pdata),
omap2_dmtimer_latency,
Expand Down Expand Up @@ -233,6 +247,7 @@ int __init omap2_system_timer_init(u8 id)
goto err_free_mem;
}
pdata->loses_context = pwrdm_can_ever_lose_context(pwrdm);
pdata->timer_errata = omap_dm_timer_get_errata();

od = omap_device_build(name, id, oh, pdata, sizeof(*pdata),
omap2_dmtimer_latency,
Expand Down
8 changes: 7 additions & 1 deletion arch/arm/mach-omap2/timer-gp.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,13 @@ static void __init omap2_gp_clockevent_init(void)

inited = 1;

gptimer = omap_dm_timer_request_specific(gptimer_id);
/*
* For clock-event timers we never read the timer counter and
* so we are not impacted by errata i103 and i767. Therefore,
* we can safely ignore this errata for clock-event timers.
*/
gptimer = __omap_dm_timer_request_specific(gptimer_id,
OMAP_TIMER_POSTED);
BUG_ON(gptimer == NULL);
gptimer_wakeup = gptimer;

Expand Down
94 changes: 80 additions & 14 deletions arch/arm/plat-omap/dmtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,45 @@ static void omap_dm_timer_write_reg(struct omap_dm_timer *timer, u32 reg,
writel(value, timer->io_base + (reg & 0xff));
}

/*
* __omap_dm_timer_enable_posted - enables write posted mode
* @timer: pointer to timer instance handle
*
* Enables the write posted mode for the timer. When posted mode is enabled
* writes to certain timer registers are immediately acknowledged by the
* internal bus and hence prevents stalling the CPU waiting for the write to
* complete. Enabling this feature can improve performance for writing to the
* timer registers.
*/
static inline void __omap_dm_timer_enable_posted(struct omap_dm_timer *timer)
{
if (timer->posted)
return;

if (timer->errata & OMAP_TIMER_ERRATA_I103_I767)
return;
omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG,
OMAP_TIMER_CTRL_POSTED);
timer->context.tsicr = OMAP_TIMER_CTRL_POSTED;
timer->posted = OMAP_TIMER_POSTED;
}

/**
* __omap_dm_timer_override_errata - override errata flags for a timer
* @timer: pointer to timer handle
* @errata: errata flags to be ignored
*
* For a given timer, override a timer errata by clearing the flags
* specified by the errata argument. A specific erratum should only be
* overridden for a timer if the timer is used in such a way the erratum
* has no impact.
*/
static inline void __omap_dm_timer_override_errata(struct omap_dm_timer *timer,
u32 errata)
{
timer->errata &= ~errata;
}

static void omap_timer_save_context(struct omap_dm_timer *timer)
{
timer->context.tiocp_cfg =
Expand Down Expand Up @@ -333,7 +372,7 @@ static void omap_dm_timer_reset(struct omap_dm_timer *timer)
__timer_disable(timer);
}

static int omap_dm_timer_prepare(struct omap_dm_timer *timer)
static int omap_dm_timer_prepare(struct omap_dm_timer *timer, int posted)
{
int ret;

Expand All @@ -358,22 +397,22 @@ static int omap_dm_timer_prepare(struct omap_dm_timer *timer)

omap_dm_timer_set_source(timer, OMAP_TIMER_SRC_32_KHZ);

end:
if (!timer->is_early_init)
__timer_enable(timer);
__timer_enable(timer);

/* Match hardware reset default of posted mode */
omap_dm_timer_write_reg(timer, OMAP_TIMER_IF_CTRL_REG,
OMAP_TIMER_CTRL_POSTED);
if (posted)
__omap_dm_timer_enable_posted(timer);

if (!timer->is_early_init)
__timer_disable(timer);
/* Check that the intended posted configuration matches the actual */
if (posted != timer->posted)
return -EINVAL;

__timer_disable(timer);

timer->posted = 1;
end:
return 0;
}

struct omap_dm_timer *omap_dm_timer_request(void)
struct omap_dm_timer *__omap_dm_timer_request(int posted)
{
struct omap_dm_timer *timer = NULL, *t;
int ret;
Expand All @@ -394,17 +433,30 @@ struct omap_dm_timer *omap_dm_timer_request(void)
pr_debug("%s: free timer not available.\n", __func__);
return NULL;
}
ret = omap_dm_timer_prepare(timer);

if (posted == OMAP_TIMER_POSTED) {
/* Assume the user knows what they're doing!
* Ignore erratum for broken posted mode timers */
__omap_dm_timer_override_errata(timer,
OMAP_TIMER_ERRATA_I103_I767);
}

ret = omap_dm_timer_prepare(timer, posted);
if (ret) {
timer->reserved = 0;
return NULL;
}

return timer;
}

struct omap_dm_timer *omap_dm_timer_request(void)
{
return __omap_dm_timer_request(OMAP_TIMER_NONPOSTED);
}
EXPORT_SYMBOL_GPL(omap_dm_timer_request);

struct omap_dm_timer *omap_dm_timer_request_specific(int id)
struct omap_dm_timer *__omap_dm_timer_request_specific(int id, int posted)
{
struct omap_dm_timer *timer = NULL, *t;
int ret;
Expand All @@ -424,14 +476,27 @@ struct omap_dm_timer *omap_dm_timer_request_specific(int id)
pr_debug("%s: timer%d not available.\n", __func__, id);
return NULL;
}
ret = omap_dm_timer_prepare(timer);

if (posted == OMAP_TIMER_POSTED) {
/* Assume the user knows what they're doing!
* Ignore erratum for broken posted mode timers */
__omap_dm_timer_override_errata(timer,
OMAP_TIMER_ERRATA_I103_I767);
}

ret = omap_dm_timer_prepare(timer, posted);
if (ret) {
timer->reserved = 0;
return NULL;
}

return timer;
}

struct omap_dm_timer *omap_dm_timer_request_specific(int id)
{
return __omap_dm_timer_request_specific(id, OMAP_TIMER_NONPOSTED);
}
EXPORT_SYMBOL_GPL(omap_dm_timer_request_specific);

int omap_dm_timer_free(struct omap_dm_timer *timer)
Expand Down Expand Up @@ -980,6 +1045,7 @@ static int __devinit omap_dm_timer_probe(struct platform_device *pdev)
timer->is_early_init = pdata->is_early_init;
timer->needs_manual_reset = pdata->needs_manual_reset;
timer->loses_context = pdata->loses_context;
timer->errata = pdata->timer_errata;

spin_lock_init(&timer->lock);
/* Skip pm_runtime_enable during early boot and for OMAP1 */
Expand Down
20 changes: 19 additions & 1 deletion arch/arm/plat-omap/include/plat/dmtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,27 @@
#define OMAP_TIMER_TRIGGER_OVERFLOW 0x01
#define OMAP_TIMER_TRIGGER_OVERFLOW_AND_COMPARE 0x02

/* posted mode types */
#define OMAP_TIMER_NONPOSTED 0x00
#define OMAP_TIMER_POSTED 0x01

/*
* IP revision identifier so that Highlander IP
* in OMAP4 can be distinguished.
*/
#define OMAP_TIMER_IP_VERSION_1 0x1
#define OMAP_TIMER_IP_VERSION_2 0x2

/*
* timer errata flags
*
* Errata i103/i767 impacts all OMAP3/4/5 devices including AM33xx. This
* errata prevents us from using posted mode on these devices, unless the
* timer counter register is never read. For more details please refer to
* the OMAP3/4/5 errata documents.
*/
#define OMAP_TIMER_ERRATA_I103_I767 0x80000000

struct omap_secure_timer_dev_attr {
bool is_secure_timer;
};
Expand Down Expand Up @@ -101,6 +115,7 @@ struct omap_dm_timer {
bool context_saved;
u32 ctx_loss_count;
struct timer_regs context;
u32 errata;
struct platform_device *pdev;
struct list_head node;

Expand All @@ -116,10 +131,14 @@ struct dmtimer_platform_data {
u32 is_early_init:1;
u32 needs_manual_reset:1;
bool loses_context;
u32 timer_errata;

};

struct omap_dm_timer *__omap_dm_timer_request(int posted);
struct omap_dm_timer *omap_dm_timer_request(void);
struct omap_dm_timer *__omap_dm_timer_request_specific(int timer_id,
int posted);
struct omap_dm_timer *omap_dm_timer_request_specific(int timer_id);
int omap_dm_timer_free(struct omap_dm_timer *timer);
int omap_dm_timer_enable(struct omap_dm_timer *timer);
Expand Down Expand Up @@ -156,5 +175,4 @@ int omap_dm_timer_write_counter(struct omap_dm_timer *timer,

int omap_dm_timers_active(void);


#endif /* __ASM_ARCH_DMTIMER_H */

0 comments on commit 4962044

Please sign in to comment.