Thomas Gleixner | 9c92ab6 | 2019-05-29 07:17:56 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 2 | /* |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 3 | * Copyright (C) 2010 Google, Inc. |
| 4 | * |
| 5 | * Author: |
| 6 | * Colin Cross <ccross@google.com> |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 7 | */ |
| 8 | |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 9 | #include <linux/clk.h> |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 10 | #include <linux/clockchips.h> |
| 11 | #include <linux/cpu.h> |
| 12 | #include <linux/cpumask.h> |
| 13 | #include <linux/delay.h> |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/interrupt.h> |
Stephen Warren | 3a04931 | 2012-10-23 11:40:25 -0600 | [diff] [blame] | 16 | #include <linux/of_address.h> |
Stephen Warren | 5641548 | 2012-09-19 13:13:33 -0600 | [diff] [blame] | 17 | #include <linux/of_irq.h> |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 18 | #include <linux/percpu.h> |
Stephen Boyd | 38ff87f | 2013-06-01 23:39:40 -0700 | [diff] [blame] | 19 | #include <linux/sched_clock.h> |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 20 | #include <linux/time.h> |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 21 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 22 | #include "timer-of.h" |
| 23 | |
| 24 | #ifdef CONFIG_ARM |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 25 | #include <asm/mach/time.h> |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 26 | #endif |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 27 | |
Colin Cross | 0936178 | 2010-11-28 16:26:19 -0800 | [diff] [blame] | 28 | #define RTC_SECONDS 0x08 |
| 29 | #define RTC_SHADOW_SECONDS 0x0c |
| 30 | #define RTC_MILLISECONDS 0x10 |
| 31 | |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 32 | #define TIMERUS_CNTR_1US 0x10 |
| 33 | #define TIMERUS_USEC_CFG 0x14 |
| 34 | #define TIMERUS_CNTR_FREEZE 0x4c |
| 35 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 36 | #define TIMER_PTV 0x0 |
| 37 | #define TIMER_PTV_EN BIT(31) |
| 38 | #define TIMER_PTV_PER BIT(30) |
| 39 | #define TIMER_PCR 0x4 |
| 40 | #define TIMER_PCR_INTR_CLR BIT(30) |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 41 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 42 | #ifdef CONFIG_ARM |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 43 | #define TIMER_CPU0 0x00 /* TIMER1 */ |
| 44 | #define TIMER_CPU2 0x50 /* TIMER3 */ |
| 45 | #define TIMER1_IRQ_IDX 0 |
| 46 | #define IRQ_IDX_FOR_CPU(cpu) (TIMER1_IRQ_IDX + cpu) |
| 47 | #define TIMER_BASE_FOR_CPU(cpu) \ |
| 48 | (((cpu) & 1) * 8 + ((cpu) < 2 ? TIMER_CPU0 : TIMER_CPU2)) |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 49 | #else |
| 50 | #define TIMER_CPU0 0x90 /* TIMER10 */ |
| 51 | #define TIMER10_IRQ_IDX 10 |
| 52 | #define IRQ_IDX_FOR_CPU(cpu) (TIMER10_IRQ_IDX + cpu) |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 53 | #define TIMER_BASE_FOR_CPU(cpu) (TIMER_CPU0 + (cpu) * 8) |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 54 | #endif |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 55 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 56 | static u32 usec_config; |
Stephen Warren | 3a04931 | 2012-10-23 11:40:25 -0600 | [diff] [blame] | 57 | static void __iomem *timer_reg_base; |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 58 | #ifdef CONFIG_ARM |
Peter De Schrijver | 0ff36b4 | 2014-06-12 18:58:29 +0300 | [diff] [blame] | 59 | static struct delay_timer tegra_delay_timer; |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 60 | #endif |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 61 | |
| 62 | static int tegra_timer_set_next_event(unsigned long cycles, |
| 63 | struct clock_event_device *evt) |
| 64 | { |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 65 | void __iomem *reg_base = timer_of_base(to_timer_of(evt)); |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 66 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 67 | writel(TIMER_PTV_EN | |
| 68 | ((cycles > 1) ? (cycles - 1) : 0), /* n+1 scheme */ |
| 69 | reg_base + TIMER_PTV); |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
Viresh Kumar | 4134d29 | 2015-07-03 14:24:35 +0530 | [diff] [blame] | 74 | static int tegra_timer_shutdown(struct clock_event_device *evt) |
| 75 | { |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 76 | void __iomem *reg_base = timer_of_base(to_timer_of(evt)); |
| 77 | |
| 78 | writel(0, reg_base + TIMER_PTV); |
| 79 | |
Viresh Kumar | 4134d29 | 2015-07-03 14:24:35 +0530 | [diff] [blame] | 80 | return 0; |
| 81 | } |
| 82 | |
| 83 | static int tegra_timer_set_periodic(struct clock_event_device *evt) |
| 84 | { |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 85 | void __iomem *reg_base = timer_of_base(to_timer_of(evt)); |
Viresh Kumar | 4134d29 | 2015-07-03 14:24:35 +0530 | [diff] [blame] | 86 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 87 | writel(TIMER_PTV_EN | TIMER_PTV_PER | |
| 88 | ((timer_of_rate(to_timer_of(evt)) / HZ) - 1), |
| 89 | reg_base + TIMER_PTV); |
| 90 | |
Viresh Kumar | 4134d29 | 2015-07-03 14:24:35 +0530 | [diff] [blame] | 91 | return 0; |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 94 | static irqreturn_t tegra_timer_isr(int irq, void *dev_id) |
| 95 | { |
| 96 | struct clock_event_device *evt = (struct clock_event_device *)dev_id; |
| 97 | void __iomem *reg_base = timer_of_base(to_timer_of(evt)); |
| 98 | |
| 99 | writel(TIMER_PCR_INTR_CLR, reg_base + TIMER_PCR); |
| 100 | evt->event_handler(evt); |
| 101 | |
| 102 | return IRQ_HANDLED; |
| 103 | } |
| 104 | |
| 105 | static void tegra_timer_suspend(struct clock_event_device *evt) |
| 106 | { |
| 107 | void __iomem *reg_base = timer_of_base(to_timer_of(evt)); |
| 108 | |
| 109 | writel(TIMER_PCR_INTR_CLR, reg_base + TIMER_PCR); |
| 110 | } |
| 111 | |
| 112 | static void tegra_timer_resume(struct clock_event_device *evt) |
| 113 | { |
| 114 | writel(usec_config, timer_reg_base + TIMERUS_USEC_CFG); |
| 115 | } |
| 116 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 117 | static DEFINE_PER_CPU(struct timer_of, tegra_to) = { |
| 118 | .flags = TIMER_OF_CLOCK | TIMER_OF_BASE, |
| 119 | |
| 120 | .clkevt = { |
| 121 | .name = "tegra_timer", |
| 122 | .rating = 460, |
| 123 | .features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC, |
| 124 | .set_next_event = tegra_timer_set_next_event, |
| 125 | .set_state_shutdown = tegra_timer_shutdown, |
| 126 | .set_state_periodic = tegra_timer_set_periodic, |
| 127 | .set_state_oneshot = tegra_timer_shutdown, |
| 128 | .tick_resume = tegra_timer_shutdown, |
| 129 | .suspend = tegra_timer_suspend, |
| 130 | .resume = tegra_timer_resume, |
| 131 | }, |
| 132 | }; |
| 133 | |
| 134 | static int tegra_timer_setup(unsigned int cpu) |
| 135 | { |
| 136 | struct timer_of *to = per_cpu_ptr(&tegra_to, cpu); |
| 137 | |
| 138 | irq_force_affinity(to->clkevt.irq, cpumask_of(cpu)); |
| 139 | enable_irq(to->clkevt.irq); |
| 140 | |
| 141 | clockevents_config_and_register(&to->clkevt, timer_of_rate(to), |
| 142 | 1, /* min */ |
| 143 | 0x1fffffff); /* 29 bits */ |
| 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static int tegra_timer_stop(unsigned int cpu) |
| 149 | { |
| 150 | struct timer_of *to = per_cpu_ptr(&tegra_to, cpu); |
| 151 | |
| 152 | to->clkevt.set_state_shutdown(&to->clkevt); |
| 153 | disable_irq_nosync(to->clkevt.irq); |
| 154 | |
| 155 | return 0; |
| 156 | } |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 157 | |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 158 | #ifdef CONFIG_ARM |
Stephen Boyd | 3570299 | 2013-07-18 16:21:26 -0700 | [diff] [blame] | 159 | static u64 notrace tegra_read_sched_clock(void) |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 160 | { |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 161 | return readl(timer_reg_base + TIMERUS_CNTR_1US); |
| 162 | } |
| 163 | |
| 164 | static unsigned long tegra_delay_timer_read_counter_long(void) |
| 165 | { |
| 166 | return readl(timer_reg_base + TIMERUS_CNTR_1US); |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Joseph Lo | 95170f0 | 2019-04-02 11:02:34 +0800 | [diff] [blame] | 169 | static struct timer_of suspend_rtc_to = { |
| 170 | .flags = TIMER_OF_BASE | TIMER_OF_CLOCK, |
| 171 | }; |
| 172 | |
Colin Cross | 0936178 | 2010-11-28 16:26:19 -0800 | [diff] [blame] | 173 | /* |
| 174 | * tegra_rtc_read - Reads the Tegra RTC registers |
| 175 | * Care must be taken that this funciton is not called while the |
| 176 | * tegra_rtc driver could be executing to avoid race conditions |
| 177 | * on the RTC shadow register |
| 178 | */ |
Joseph Lo | 95170f0 | 2019-04-02 11:02:34 +0800 | [diff] [blame] | 179 | static u64 tegra_rtc_read_ms(struct clocksource *cs) |
Colin Cross | 0936178 | 2010-11-28 16:26:19 -0800 | [diff] [blame] | 180 | { |
Joseph Lo | 95170f0 | 2019-04-02 11:02:34 +0800 | [diff] [blame] | 181 | u32 ms = readl(timer_of_base(&suspend_rtc_to) + RTC_MILLISECONDS); |
| 182 | u32 s = readl(timer_of_base(&suspend_rtc_to) + RTC_SHADOW_SECONDS); |
Colin Cross | 0936178 | 2010-11-28 16:26:19 -0800 | [diff] [blame] | 183 | return (u64)s * MSEC_PER_SEC + ms; |
| 184 | } |
| 185 | |
Joseph Lo | 95170f0 | 2019-04-02 11:02:34 +0800 | [diff] [blame] | 186 | static struct clocksource suspend_rtc_clocksource = { |
| 187 | .name = "tegra_suspend_timer", |
| 188 | .rating = 200, |
| 189 | .read = tegra_rtc_read_ms, |
| 190 | .mask = CLOCKSOURCE_MASK(32), |
| 191 | .flags = CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTOP, |
| 192 | }; |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 193 | #endif |
Xunlei Pang | a0c2998 | 2015-04-01 20:34:25 -0700 | [diff] [blame] | 194 | |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 195 | static int tegra_init_timer(struct device_node *np, bool tegra20) |
Peter De Schrijver | 0ff36b4 | 2014-06-12 18:58:29 +0300 | [diff] [blame] | 196 | { |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 197 | struct timer_of *to; |
| 198 | int cpu, ret; |
Peter De Schrijver | 0ff36b4 | 2014-06-12 18:58:29 +0300 | [diff] [blame] | 199 | |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 200 | to = this_cpu_ptr(&tegra_to); |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 201 | ret = timer_of_init(np, to); |
| 202 | if (ret < 0) |
| 203 | goto out; |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 204 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 205 | timer_reg_base = timer_of_base(to); |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 206 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 207 | /* |
| 208 | * Configure microsecond timers to have 1MHz clock |
| 209 | * Config register is 0xqqww, where qq is "dividend", ww is "divisor" |
| 210 | * Uses n+1 scheme |
| 211 | */ |
| 212 | switch (timer_of_rate(to)) { |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 213 | case 12000000: |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 214 | usec_config = 0x000b; /* (11+1)/(0+1) */ |
| 215 | break; |
| 216 | case 12800000: |
| 217 | usec_config = 0x043f; /* (63+1)/(4+1) */ |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 218 | break; |
| 219 | case 13000000: |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 220 | usec_config = 0x000c; /* (12+1)/(0+1) */ |
| 221 | break; |
| 222 | case 16800000: |
| 223 | usec_config = 0x0453; /* (83+1)/(4+1) */ |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 224 | break; |
| 225 | case 19200000: |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 226 | usec_config = 0x045f; /* (95+1)/(4+1) */ |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 227 | break; |
| 228 | case 26000000: |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 229 | usec_config = 0x0019; /* (25+1)/(0+1) */ |
| 230 | break; |
| 231 | case 38400000: |
| 232 | usec_config = 0x04bf; /* (191+1)/(4+1) */ |
| 233 | break; |
| 234 | case 48000000: |
| 235 | usec_config = 0x002f; /* (47+1)/(0+1) */ |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 236 | break; |
| 237 | default: |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 238 | ret = -EINVAL; |
| 239 | goto out; |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 240 | } |
| 241 | |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 242 | writel(usec_config, timer_reg_base + TIMERUS_USEC_CFG); |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 243 | |
| 244 | for_each_possible_cpu(cpu) { |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 245 | struct timer_of *cpu_to = per_cpu_ptr(&tegra_to, cpu); |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 246 | |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 247 | /* |
| 248 | * TIMER1-9 are fixed to 1MHz, TIMER10-13 are running off the |
| 249 | * parent clock. |
| 250 | */ |
| 251 | if (tegra20) |
| 252 | cpu_to->of_clk.rate = 1000000; |
| 253 | |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 254 | cpu_to->of_base.base = timer_reg_base + TIMER_BASE_FOR_CPU(cpu); |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 255 | cpu_to->clkevt.cpumask = cpumask_of(cpu); |
| 256 | cpu_to->clkevt.irq = |
| 257 | irq_of_parse_and_map(np, IRQ_IDX_FOR_CPU(cpu)); |
| 258 | if (!cpu_to->clkevt.irq) { |
| 259 | pr_err("%s: can't map IRQ for CPU%d\n", |
| 260 | __func__, cpu); |
| 261 | ret = -EINVAL; |
| 262 | goto out; |
| 263 | } |
| 264 | |
| 265 | irq_set_status_flags(cpu_to->clkevt.irq, IRQ_NOAUTOEN); |
| 266 | ret = request_irq(cpu_to->clkevt.irq, tegra_timer_isr, |
| 267 | IRQF_TIMER | IRQF_NOBALANCING, |
| 268 | cpu_to->clkevt.name, &cpu_to->clkevt); |
| 269 | if (ret) { |
| 270 | pr_err("%s: cannot setup irq %d for CPU%d\n", |
| 271 | __func__, cpu_to->clkevt.irq, cpu); |
| 272 | ret = -EINVAL; |
| 273 | goto out_irq; |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | cpuhp_setup_state(CPUHP_AP_TEGRA_TIMER_STARTING, |
| 278 | "AP_TEGRA_TIMER_STARTING", tegra_timer_setup, |
| 279 | tegra_timer_stop); |
| 280 | |
| 281 | return ret; |
| 282 | out_irq: |
| 283 | for_each_possible_cpu(cpu) { |
| 284 | struct timer_of *cpu_to; |
| 285 | |
| 286 | cpu_to = per_cpu_ptr(&tegra_to, cpu); |
| 287 | if (cpu_to->clkevt.irq) { |
| 288 | free_irq(cpu_to->clkevt.irq, &cpu_to->clkevt); |
| 289 | irq_dispose_mapping(cpu_to->clkevt.irq); |
| 290 | } |
| 291 | } |
| 292 | out: |
| 293 | timer_of_cleanup(to); |
| 294 | return ret; |
| 295 | } |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 296 | |
| 297 | #ifdef CONFIG_ARM64 |
| 298 | static int __init tegra210_init_timer(struct device_node *np) |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 299 | { |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 300 | return tegra_init_timer(np, false); |
| 301 | } |
| 302 | TIMER_OF_DECLARE(tegra210_timer, "nvidia,tegra210-timer", tegra210_init_timer); |
| 303 | #else /* CONFIG_ARM */ |
| 304 | static int __init tegra20_init_timer(struct device_node *np) |
| 305 | { |
| 306 | struct timer_of *to; |
| 307 | int err; |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 308 | |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 309 | err = tegra_init_timer(np, true); |
| 310 | if (err) |
| 311 | return err; |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 312 | |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 313 | to = this_cpu_ptr(&tegra_to); |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 314 | |
| 315 | sched_clock_register(tegra_read_sched_clock, 32, |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 316 | timer_of_rate(to)); |
| 317 | err = clocksource_mmio_init(timer_reg_base + TIMERUS_CNTR_1US, |
| 318 | "timer_us", timer_of_rate(to), |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 319 | 300, 32, clocksource_mmio_readl_up); |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 320 | if (err) |
| 321 | pr_err("Failed to register clocksource: %d\n", err); |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 322 | |
Peter De Schrijver | 0ff36b4 | 2014-06-12 18:58:29 +0300 | [diff] [blame] | 323 | tegra_delay_timer.read_current_timer = |
| 324 | tegra_delay_timer_read_counter_long; |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 325 | tegra_delay_timer.freq = timer_of_rate(to); |
Peter De Schrijver | 0ff36b4 | 2014-06-12 18:58:29 +0300 | [diff] [blame] | 326 | register_current_timer_delay(&tegra_delay_timer); |
| 327 | |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 328 | return 0; |
Daniel Lezcano | 53978bb | 2016-06-06 17:59:43 +0200 | [diff] [blame] | 329 | } |
Daniel Lezcano | 53978bb | 2016-06-06 17:59:43 +0200 | [diff] [blame] | 330 | |
| 331 | static int __init tegra20_init_rtc(struct device_node *np) |
Rob Herring | 1d16cfb | 2013-02-07 11:36:23 -0600 | [diff] [blame] | 332 | { |
Joseph Lo | 95170f0 | 2019-04-02 11:02:34 +0800 | [diff] [blame] | 333 | int ret; |
Rob Herring | 1d16cfb | 2013-02-07 11:36:23 -0600 | [diff] [blame] | 334 | |
Joseph Lo | 95170f0 | 2019-04-02 11:02:34 +0800 | [diff] [blame] | 335 | ret = timer_of_init(np, &suspend_rtc_to); |
| 336 | if (ret) |
| 337 | return ret; |
Rob Herring | 1d16cfb | 2013-02-07 11:36:23 -0600 | [diff] [blame] | 338 | |
Joseph Lo | 95170f0 | 2019-04-02 11:02:34 +0800 | [diff] [blame] | 339 | clocksource_register_hz(&suspend_rtc_clocksource, 1000); |
Rob Herring | 1d16cfb | 2013-02-07 11:36:23 -0600 | [diff] [blame] | 340 | |
Joseph Lo | 95170f0 | 2019-04-02 11:02:34 +0800 | [diff] [blame] | 341 | return 0; |
Colin Cross | 2d5cd9a | 2010-01-28 16:41:42 -0800 | [diff] [blame] | 342 | } |
Daniel Lezcano | 1727339 | 2017-05-26 16:56:11 +0200 | [diff] [blame] | 343 | TIMER_OF_DECLARE(tegra20_rtc, "nvidia,tegra20-rtc", tegra20_init_rtc); |
Dmitry Osipenko | f6d50ec | 2019-06-03 21:59:39 +0300 | [diff] [blame^] | 344 | TIMER_OF_DECLARE(tegra20_timer, "nvidia,tegra20-timer", tegra20_init_timer); |
Joseph Lo | b4822dc | 2019-02-21 15:21:44 +0800 | [diff] [blame] | 345 | #endif |