blob: 5fa3848ba22497c34d68e4f0e3f4069f79c73d09 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/module.h>
2#include <linux/smp.h>
3#include <linux/time.h>
4#include <linux/errno.h>
Tim Schmielau4e57b682005-10-30 15:03:48 -08005#include <linux/timex.h>
Tony Luck0aa366f2007-07-20 11:22:30 -07006#include <linux/clocksource.h>
Dan Williams2584cf82015-08-10 23:07:05 -04007#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9/* IBM Summit (EXA) Cyclone counter code*/
10#define CYCLONE_CBAR_ADDR 0xFEB00CD0
11#define CYCLONE_PMCC_OFFSET 0x51A0
12#define CYCLONE_MPMC_OFFSET 0x51D0
13#define CYCLONE_MPCS_OFFSET 0x51A8
14#define CYCLONE_TIMER_FREQ 100000000
15
16int use_cyclone;
17void __init cyclone_setup(void)
18{
19 use_cyclone = 1;
20}
21
Tony Luck0aa366f2007-07-20 11:22:30 -070022static void __iomem *cyclone_mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Magnus Damm8e196082009-04-21 12:24:00 -070024static cycle_t read_cyclone(struct clocksource *cs)
Tony Luck0aa366f2007-07-20 11:22:30 -070025{
26 return (cycle_t)readq((void __iomem *)cyclone_mc);
27}
28
29static struct clocksource clocksource_cyclone = {
30 .name = "cyclone",
31 .rating = 300,
32 .read = read_cyclone,
33 .mask = (1LL << 40) - 1,
Tony Luck0aa366f2007-07-20 11:22:30 -070034 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
Linus Torvalds1da177e2005-04-16 15:20:36 -070035};
36
37int __init init_cyclone_clock(void)
38{
Al Viro6aa8b042007-07-26 17:34:59 +010039 u64 __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 u64 base; /* saved cyclone base address */
41 u64 offset; /* offset from pageaddr to cyclone_timer register */
42 int i;
Al Viro6aa8b042007-07-26 17:34:59 +010043 u32 __iomem *cyclone_timer; /* Cyclone MPMC0 register */
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45 if (!use_cyclone)
Bjorn Helgaas6c5e6212006-03-03 15:33:47 -070046 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48 printk(KERN_INFO "Summit chipset: Starting Cyclone Counter.\n");
49
50 /* find base address */
51 offset = (CYCLONE_CBAR_ADDR);
Al Viro6aa8b042007-07-26 17:34:59 +010052 reg = ioremap_nocache(offset, sizeof(u64));
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 if(!reg){
Tony Luck0aa366f2007-07-20 11:22:30 -070054 printk(KERN_ERR "Summit chipset: Could not find valid CBAR"
55 " register.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 use_cyclone = 0;
57 return -ENODEV;
58 }
59 base = readq(reg);
Julia Lawallddad53e2010-08-27 23:01:30 +020060 iounmap(reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 if(!base){
Tony Luck0aa366f2007-07-20 11:22:30 -070062 printk(KERN_ERR "Summit chipset: Could not find valid CBAR"
63 " value.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 use_cyclone = 0;
65 return -ENODEV;
66 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 /* setup PMCC */
69 offset = (base + CYCLONE_PMCC_OFFSET);
Al Viro6aa8b042007-07-26 17:34:59 +010070 reg = ioremap_nocache(offset, sizeof(u64));
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 if(!reg){
Tony Luck0aa366f2007-07-20 11:22:30 -070072 printk(KERN_ERR "Summit chipset: Could not find valid PMCC"
73 " register.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 use_cyclone = 0;
75 return -ENODEV;
76 }
77 writel(0x00000001,reg);
78 iounmap(reg);
79
80 /* setup MPCS */
81 offset = (base + CYCLONE_MPCS_OFFSET);
Al Viro6aa8b042007-07-26 17:34:59 +010082 reg = ioremap_nocache(offset, sizeof(u64));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 if(!reg){
Tony Luck0aa366f2007-07-20 11:22:30 -070084 printk(KERN_ERR "Summit chipset: Could not find valid MPCS"
85 " register.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 use_cyclone = 0;
87 return -ENODEV;
88 }
89 writel(0x00000001,reg);
90 iounmap(reg);
91
92 /* map in cyclone_timer */
93 offset = (base + CYCLONE_MPMC_OFFSET);
Al Viro6aa8b042007-07-26 17:34:59 +010094 cyclone_timer = ioremap_nocache(offset, sizeof(u32));
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 if(!cyclone_timer){
Tony Luck0aa366f2007-07-20 11:22:30 -070096 printk(KERN_ERR "Summit chipset: Could not find valid MPMC"
97 " register.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 use_cyclone = 0;
99 return -ENODEV;
100 }
101
102 /*quick test to make sure its ticking*/
103 for(i=0; i<3; i++){
104 u32 old = readl(cyclone_timer);
105 int stall = 100;
106 while(stall--) barrier();
107 if(readl(cyclone_timer) == old){
Tony Luck0aa366f2007-07-20 11:22:30 -0700108 printk(KERN_ERR "Summit chipset: Counter not counting!"
109 " DISABLED\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 iounmap(cyclone_timer);
Al Viro6aa8b042007-07-26 17:34:59 +0100111 cyclone_timer = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 use_cyclone = 0;
113 return -ENODEV;
114 }
115 }
116 /* initialize last tick */
Tony Luck0aa366f2007-07-20 11:22:30 -0700117 cyclone_mc = cyclone_timer;
Andy Lutomirski574c44f2011-07-13 09:24:15 -0400118 clocksource_cyclone.archdata.fsys_mmio = cyclone_timer;
John Stultzd60c3042010-04-26 20:20:47 -0700119 clocksource_register_hz(&clocksource_cyclone, CYCLONE_TIMER_FREQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 return 0;
122}
123
124__initcall(init_cyclone_clock);