Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #include <linux/module.h> |
| 3 | #include <linux/smp.h> |
| 4 | #include <linux/time.h> |
| 5 | #include <linux/errno.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 6 | #include <linux/timex.h> |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 7 | #include <linux/clocksource.h> |
Dan Williams | 2584cf8 | 2015-08-10 23:07:05 -0400 | [diff] [blame] | 8 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 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 |
| 16 | |
| 17 | int use_cyclone; |
| 18 | void __init cyclone_setup(void) |
| 19 | { |
| 20 | use_cyclone = 1; |
| 21 | } |
| 22 | |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 23 | static void __iomem *cyclone_mc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 25 | static u64 read_cyclone(struct clocksource *cs) |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 26 | { |
Thomas Gleixner | a5a1d1c | 2016-12-21 20:32:01 +0100 | [diff] [blame] | 27 | return (u64)readq((void __iomem *)cyclone_mc); |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | static struct clocksource clocksource_cyclone = { |
| 31 | .name = "cyclone", |
| 32 | .rating = 300, |
| 33 | .read = read_cyclone, |
| 34 | .mask = (1LL << 40) - 1, |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 35 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | }; |
| 37 | |
| 38 | int __init init_cyclone_clock(void) |
| 39 | { |
Al Viro | 6aa8b04 | 2007-07-26 17:34:59 +0100 | [diff] [blame] | 40 | u64 __iomem *reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | u64 base; /* saved cyclone base address */ |
| 42 | u64 offset; /* offset from pageaddr to cyclone_timer register */ |
| 43 | int i; |
Al Viro | 6aa8b04 | 2007-07-26 17:34:59 +0100 | [diff] [blame] | 44 | u32 __iomem *cyclone_timer; /* Cyclone MPMC0 register */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | if (!use_cyclone) |
Bjorn Helgaas | 6c5e621 | 2006-03-03 15:33:47 -0700 | [diff] [blame] | 47 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | printk(KERN_INFO "Summit chipset: Starting Cyclone Counter.\n"); |
| 50 | |
| 51 | /* find base address */ |
| 52 | offset = (CYCLONE_CBAR_ADDR); |
Al Viro | 6aa8b04 | 2007-07-26 17:34:59 +0100 | [diff] [blame] | 53 | reg = ioremap_nocache(offset, sizeof(u64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | if(!reg){ |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 55 | printk(KERN_ERR "Summit chipset: Could not find valid CBAR" |
| 56 | " register.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | use_cyclone = 0; |
| 58 | return -ENODEV; |
| 59 | } |
| 60 | base = readq(reg); |
Julia Lawall | ddad53e | 2010-08-27 23:01:30 +0200 | [diff] [blame] | 61 | iounmap(reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | if(!base){ |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 63 | printk(KERN_ERR "Summit chipset: Could not find valid CBAR" |
| 64 | " value.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | use_cyclone = 0; |
| 66 | return -ENODEV; |
| 67 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | /* setup PMCC */ |
| 70 | offset = (base + CYCLONE_PMCC_OFFSET); |
Al Viro | 6aa8b04 | 2007-07-26 17:34:59 +0100 | [diff] [blame] | 71 | reg = ioremap_nocache(offset, sizeof(u64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | if(!reg){ |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 73 | printk(KERN_ERR "Summit chipset: Could not find valid PMCC" |
| 74 | " register.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | use_cyclone = 0; |
| 76 | return -ENODEV; |
| 77 | } |
| 78 | writel(0x00000001,reg); |
| 79 | iounmap(reg); |
| 80 | |
| 81 | /* setup MPCS */ |
| 82 | offset = (base + CYCLONE_MPCS_OFFSET); |
Al Viro | 6aa8b04 | 2007-07-26 17:34:59 +0100 | [diff] [blame] | 83 | reg = ioremap_nocache(offset, sizeof(u64)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | if(!reg){ |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 85 | printk(KERN_ERR "Summit chipset: Could not find valid MPCS" |
| 86 | " register.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | use_cyclone = 0; |
| 88 | return -ENODEV; |
| 89 | } |
| 90 | writel(0x00000001,reg); |
| 91 | iounmap(reg); |
| 92 | |
| 93 | /* map in cyclone_timer */ |
| 94 | offset = (base + CYCLONE_MPMC_OFFSET); |
Al Viro | 6aa8b04 | 2007-07-26 17:34:59 +0100 | [diff] [blame] | 95 | cyclone_timer = ioremap_nocache(offset, sizeof(u32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | if(!cyclone_timer){ |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 97 | printk(KERN_ERR "Summit chipset: Could not find valid MPMC" |
| 98 | " register.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | use_cyclone = 0; |
| 100 | return -ENODEV; |
| 101 | } |
| 102 | |
| 103 | /*quick test to make sure its ticking*/ |
| 104 | for(i=0; i<3; i++){ |
| 105 | u32 old = readl(cyclone_timer); |
| 106 | int stall = 100; |
| 107 | while(stall--) barrier(); |
| 108 | if(readl(cyclone_timer) == old){ |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 109 | printk(KERN_ERR "Summit chipset: Counter not counting!" |
| 110 | " DISABLED\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | iounmap(cyclone_timer); |
Al Viro | 6aa8b04 | 2007-07-26 17:34:59 +0100 | [diff] [blame] | 112 | cyclone_timer = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | use_cyclone = 0; |
| 114 | return -ENODEV; |
| 115 | } |
| 116 | } |
| 117 | /* initialize last tick */ |
Tony Luck | 0aa366f | 2007-07-20 11:22:30 -0700 | [diff] [blame] | 118 | cyclone_mc = cyclone_timer; |
Andy Lutomirski | 574c44f | 2011-07-13 09:24:15 -0400 | [diff] [blame] | 119 | clocksource_cyclone.archdata.fsys_mmio = cyclone_timer; |
John Stultz | d60c304 | 2010-04-26 20:20:47 -0700 | [diff] [blame] | 120 | clocksource_register_hz(&clocksource_cyclone, CYCLONE_TIMER_FREQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | __initcall(init_cyclone_clock); |