Commit c44bf4e8ac2610d650bad441a1dc6a617ae98a4f

Authored by Heiko Schocher
Committed by Albert Aribaud
1 parent 386ad72637

arm1136: timer: Replace bss variable by gd

Reuse the gd->tbl value for timestamp and add gd->lastinc for lastinc bss
values in the arm1136 timer driver for mx31 and omap24xx

The usage of bss values in drivers before initialisation of bss is forbidden.
In that special case some data in .rel.dyn gets corrupted.

This patch is similiar to the patch Dirk Behme posted
for the armv7/omap-common/timer.c

Tested on the mx31 based qong board

Signed-off-by: Heiko Schocher <hs@denx.de>
cc: Albert ARIBAUD <albert.aribaud@free.fr>
Acked-by: Albert ARIBAUD <albert.aribaud@free.fr>

Showing 2 changed files with 18 additions and 20 deletions Side-by-side Diff

arch/arm/cpu/arm1136/mx31/timer.c
... ... @@ -39,8 +39,7 @@
39 39 #define GPTCR_CLKSOURCE_32 (4 << 6) /* Clock source */
40 40 #define GPTCR_TEN 1 /* Timer enable */
41 41  
42   -static ulong timestamp;
43   -static ulong lastinc;
  42 +DECLARE_GLOBAL_DATA_PTR;
44 43  
45 44 /* "time" is measured in 1 / CONFIG_SYS_HZ seconds, "tick" is internal timer period */
46 45 #ifdef CONFIG_MX31_TIMER_HIGH_PRECISION
... ... @@ -108,8 +107,8 @@
108 107 void reset_timer_masked (void)
109 108 {
110 109 /* reset time */
111   - lastinc = GPTCNT; /* capture current incrementer value time */
112   - timestamp = 0; /* start "advancing" time stamp from 0 */
  110 + gd->lastinc = GPTCNT; /* capture current incrementer value time */
  111 + gd->tbl = 0; /* start "advancing" time stamp from 0 */
113 112 }
114 113  
115 114 void reset_timer(void)
116 115  
117 116  
... ... @@ -121,13 +120,13 @@
121 120 {
122 121 ulong now = GPTCNT; /* current tick value */
123 122  
124   - if (now >= lastinc) /* normal mode (non roll) */
  123 + if (now >= gd->lastinc) /* normal mode (non roll) */
125 124 /* move stamp forward with absolut diff ticks */
126   - timestamp += (now - lastinc);
  125 + gd->tbl += (now - gd->lastinc);
127 126 else /* we have rollover of incrementer */
128   - timestamp += (0xFFFFFFFF - lastinc) + now;
129   - lastinc = now;
130   - return timestamp;
  127 + gd->tbl += (0xFFFFFFFF - gd->lastinc) + now;
  128 + gd->lastinc = now;
  129 + return gd->tbl;
131 130 }
132 131  
133 132 ulong get_timer_masked (void)
... ... @@ -148,7 +147,7 @@
148 147  
149 148 void set_timer (ulong t)
150 149 {
151   - timestamp = time_to_tick(t);
  150 + gd->tbl = time_to_tick(t);
152 151 }
153 152  
154 153 /* delay x useconds AND preserve advance timestamp value */
arch/arm/cpu/arm1136/omap24xx/timer.c
... ... @@ -39,8 +39,7 @@
39 39 /* macro to read the 32 bit timer */
40 40 #define READ_TIMER (*((volatile ulong *)(CONFIG_SYS_TIMERBASE+TCRR)))
41 41  
42   -static ulong timestamp;
43   -static ulong lastinc;
  42 +DECLARE_GLOBAL_DATA_PTR;
44 43  
45 44 int timer_init (void)
46 45 {
... ... @@ -70,7 +69,7 @@
70 69  
71 70 void set_timer (ulong t)
72 71 {
73   - timestamp = t;
  72 + gd->tbl = t;
74 73 }
75 74  
76 75 /* delay x useconds AND preserve advance timestamp value */
77 76  
78 77  
... ... @@ -99,20 +98,20 @@
99 98 void reset_timer_masked (void)
100 99 {
101 100 /* reset time */
102   - lastinc = READ_TIMER; /* capture current incrementer value time */
103   - timestamp = 0; /* start "advancing" time stamp from 0 */
  101 + gd->lastinc = READ_TIMER; /* capture current incrementer value time */
  102 + gd->tbl = 0; /* start "advancing" time stamp from 0 */
104 103 }
105 104  
106 105 ulong get_timer_masked (void)
107 106 {
108 107 ulong now = READ_TIMER; /* current tick value */
109 108  
110   - if (now >= lastinc) /* normal mode (non roll) */
111   - timestamp += (now - lastinc); /* move stamp fordward with absoulte diff ticks */
  109 + if (now >= gd->lastinc) /* normal mode (non roll) */
  110 + gd->tbl += (now - gd->lastinc); /* move stamp fordward with absoulte diff ticks */
112 111 else /* we have rollover of incrementer */
113   - timestamp += (0xFFFFFFFF - lastinc) + now;
114   - lastinc = now;
115   - return timestamp;
  112 + gd->tbl += (0xFFFFFFFF - gd->lastinc) + now;
  113 + gd->lastinc = now;
  114 + return gd->tbl;
116 115 }
117 116  
118 117 /* waits specified delay value and resets timestamp */