@@ -43,21 +43,44 @@ static unsigned int timer_clock_freq;
4343#define TCSR_PWMA (1<<9)
4444#define TCSR_ENALL (1<<10)
4545
46+ static unsigned int (* read_fn )(void __iomem * );
47+ static void (* write_fn )(u32 , void __iomem * );
48+
49+ static void timer_write32 (u32 val , void __iomem * addr )
50+ {
51+ iowrite32 (val , addr );
52+ }
53+
54+ static unsigned int timer_read32 (void __iomem * addr )
55+ {
56+ return ioread32 (addr );
57+ }
58+
59+ static void timer_write32_be (u32 val , void __iomem * addr )
60+ {
61+ iowrite32be (val , addr );
62+ }
63+
64+ static unsigned int timer_read32_be (void __iomem * addr )
65+ {
66+ return ioread32be (addr );
67+ }
68+
4669static inline void xilinx_timer0_stop (void )
4770{
48- out_be32 ( timer_baseaddr + TCSR0 ,
49- in_be32 ( timer_baseaddr + TCSR0 ) & ~ TCSR_ENT );
71+ write_fn ( read_fn ( timer_baseaddr + TCSR0 ) & ~ TCSR_ENT ,
72+ timer_baseaddr + TCSR0 );
5073}
5174
5275static inline void xilinx_timer0_start_periodic (unsigned long load_val )
5376{
5477 if (!load_val )
5578 load_val = 1 ;
5679 /* loading value to timer reg */
57- out_be32 ( timer_baseaddr + TLR0 , load_val );
80+ write_fn ( load_val , timer_baseaddr + TLR0 );
5881
5982 /* load the initial value */
60- out_be32 ( timer_baseaddr + TCSR0 , TCSR_LOAD );
83+ write_fn ( TCSR_LOAD , timer_baseaddr + TCSR0 );
6184
6285 /* see timer data sheet for detail
6386 * !ENALL - don't enable 'em all
@@ -72,22 +95,22 @@ static inline void xilinx_timer0_start_periodic(unsigned long load_val)
7295 * UDT - set the timer as down counter
7396 * !MDT0 - generate mode
7497 */
75- out_be32 ( timer_baseaddr + TCSR0 ,
76- TCSR_TINT | TCSR_ENIT | TCSR_ENT | TCSR_ARHT | TCSR_UDT );
98+ write_fn ( TCSR_TINT | TCSR_ENIT | TCSR_ENT | TCSR_ARHT | TCSR_UDT ,
99+ timer_baseaddr + TCSR0 );
77100}
78101
79102static inline void xilinx_timer0_start_oneshot (unsigned long load_val )
80103{
81104 if (!load_val )
82105 load_val = 1 ;
83106 /* loading value to timer reg */
84- out_be32 ( timer_baseaddr + TLR0 , load_val );
107+ write_fn ( load_val , timer_baseaddr + TLR0 );
85108
86109 /* load the initial value */
87- out_be32 ( timer_baseaddr + TCSR0 , TCSR_LOAD );
110+ write_fn ( TCSR_LOAD , timer_baseaddr + TCSR0 );
88111
89- out_be32 ( timer_baseaddr + TCSR0 ,
90- TCSR_TINT | TCSR_ENIT | TCSR_ENT | TCSR_ARHT | TCSR_UDT );
112+ write_fn ( TCSR_TINT | TCSR_ENIT | TCSR_ENT | TCSR_ARHT | TCSR_UDT ,
113+ timer_baseaddr + TCSR0 );
91114}
92115
93116static int xilinx_timer_set_next_event (unsigned long delta ,
@@ -133,7 +156,7 @@ static struct clock_event_device clockevent_xilinx_timer = {
133156
134157static inline void timer_ack (void )
135158{
136- out_be32 ( timer_baseaddr + TCSR0 , in_be32 ( timer_baseaddr + TCSR0 ) );
159+ write_fn ( read_fn ( timer_baseaddr + TCSR0 ), timer_baseaddr + TCSR0 );
137160}
138161
139162static irqreturn_t timer_interrupt (int irq , void * dev_id )
@@ -169,7 +192,7 @@ static __init void xilinx_clockevent_init(void)
169192
170193static u64 xilinx_clock_read (void )
171194{
172- return in_be32 (timer_baseaddr + TCR1 );
195+ return read_fn (timer_baseaddr + TCR1 );
173196}
174197
175198static cycle_t xilinx_read (struct clocksource * cs )
@@ -217,10 +240,10 @@ static int __init xilinx_clocksource_init(void)
217240 panic ("failed to register clocksource" );
218241
219242 /* stop timer1 */
220- out_be32 ( timer_baseaddr + TCSR1 ,
221- in_be32 ( timer_baseaddr + TCSR1 ) & ~ TCSR_ENT );
243+ write_fn ( read_fn ( timer_baseaddr + TCSR1 ) & ~ TCSR_ENT ,
244+ timer_baseaddr + TCSR1 );
222245 /* start timer1 - up counting without interrupt */
223- out_be32 ( timer_baseaddr + TCSR1 , TCSR_TINT |TCSR_ENT |TCSR_ARHT );
246+ write_fn ( TCSR_TINT |TCSR_ENT |TCSR_ARHT , timer_baseaddr + TCSR1 );
224247
225248 /* register timecounter - for ftrace support */
226249 init_xilinx_timecounter ();
@@ -245,6 +268,15 @@ static void __init xilinx_timer_init(struct device_node *timer)
245268 BUG ();
246269 }
247270
271+ write_fn = timer_write32 ;
272+ read_fn = timer_read32 ;
273+
274+ write_fn (TCSR_MDT , timer_baseaddr + TCSR0 );
275+ if (!(read_fn (timer_baseaddr + TCSR0 ) & TCSR_MDT )) {
276+ write_fn = timer_write32_be ;
277+ read_fn = timer_read32_be ;
278+ }
279+
248280 irq = irq_of_parse_and_map (timer , 0 );
249281
250282 of_property_read_u32 (timer , "xlnx,one-timer-only" , & timer_num );
0 commit comments