1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/module.h>
4 #include <linux/time.h>
5 #include <linux/errno.h>
6 #include <linux/timex.h>
7 #include <linux/clocksource.h>
10 /* IBM Summit (EXA) Cyclone counter code*/
11 #define CYCLONE_CBAR_ADDR 0xFEB00CD0
12 #define CYCLONE_PMCC_OFFSET 0x51A0
13 #define CYCLONE_MPMC_OFFSET 0x51D0
14 #define CYCLONE_MPCS_OFFSET 0x51A8
15 #define CYCLONE_TIMER_FREQ 100000000
18 void __init
cyclone_setup(void)
23 static void __iomem
*cyclone_mc
;
25 static u64
read_cyclone(struct clocksource
*cs
)
27 return (u64
)readq((void __iomem
*)cyclone_mc
);
30 static struct clocksource clocksource_cyclone
= {
34 .mask
= (1LL << 40) - 1,
35 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
38 int __init
init_cyclone_clock(void)
41 u64 base
; /* saved cyclone base address */
42 u64 offset
; /* offset from pageaddr to cyclone_timer register */
44 u32 __iomem
*cyclone_timer
; /* Cyclone MPMC0 register */
49 printk(KERN_INFO
"Summit chipset: Starting Cyclone Counter.\n");
51 /* find base address */
52 offset
= (CYCLONE_CBAR_ADDR
);
53 reg
= ioremap(offset
, sizeof(u64
));
55 printk(KERN_ERR
"Summit chipset: Could not find valid CBAR"
63 printk(KERN_ERR
"Summit chipset: Could not find valid CBAR"
70 offset
= (base
+ CYCLONE_PMCC_OFFSET
);
71 reg
= ioremap(offset
, sizeof(u64
));
73 printk(KERN_ERR
"Summit chipset: Could not find valid PMCC"
78 writel(0x00000001,reg
);
82 offset
= (base
+ CYCLONE_MPCS_OFFSET
);
83 reg
= ioremap(offset
, sizeof(u64
));
85 printk(KERN_ERR
"Summit chipset: Could not find valid MPCS"
90 writel(0x00000001,reg
);
93 /* map in cyclone_timer */
94 offset
= (base
+ CYCLONE_MPMC_OFFSET
);
95 cyclone_timer
= ioremap(offset
, sizeof(u32
));
97 printk(KERN_ERR
"Summit chipset: Could not find valid MPMC"
103 /*quick test to make sure its ticking*/
105 u32 old
= readl(cyclone_timer
);
107 while(stall
--) barrier();
108 if(readl(cyclone_timer
) == old
){
109 printk(KERN_ERR
"Summit chipset: Counter not counting!"
111 iounmap(cyclone_timer
);
112 cyclone_timer
= NULL
;
117 /* initialize last tick */
118 cyclone_mc
= cyclone_timer
;
119 clocksource_cyclone
.archdata
.fsys_mmio
= cyclone_timer
;
120 clocksource_register_hz(&clocksource_cyclone
, CYCLONE_TIMER_FREQ
);
125 __initcall(init_cyclone_clock
);