.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /** |
---|
2 | 3 | * timer-ti-32k.c - OMAP2 32k Timer Support |
---|
3 | 4 | * |
---|
.. | .. |
---|
20 | 21 | * Roughly modelled after the OMAP1 MPU timer code. |
---|
21 | 22 | * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com> |
---|
22 | 23 | * |
---|
23 | | - * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com |
---|
24 | | - * |
---|
25 | | - * This program is free software: you can redistribute it and/or modify |
---|
26 | | - * it under the terms of the GNU General Public License version 2 of |
---|
27 | | - * the License as published by the Free Software Foundation. |
---|
28 | | - * |
---|
29 | | - * This program is distributed in the hope that it will be useful, |
---|
30 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
31 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
32 | | - * GNU General Public License for more details. |
---|
33 | | - * |
---|
34 | | - * You should have received a copy of the GNU General Public License |
---|
35 | | - * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 24 | + * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com |
---|
36 | 25 | */ |
---|
37 | 26 | |
---|
| 27 | +#include <linux/clk.h> |
---|
38 | 28 | #include <linux/init.h> |
---|
39 | 29 | #include <linux/time.h> |
---|
40 | 30 | #include <linux/sched_clock.h> |
---|
.. | .. |
---|
87 | 77 | return ti_32k_read_cycles(&ti_32k_timer.cs); |
---|
88 | 78 | } |
---|
89 | 79 | |
---|
| 80 | +static void __init ti_32k_timer_enable_clock(struct device_node *np, |
---|
| 81 | + const char *name) |
---|
| 82 | +{ |
---|
| 83 | + struct clk *clock; |
---|
| 84 | + int error; |
---|
| 85 | + |
---|
| 86 | + clock = of_clk_get_by_name(np->parent, name); |
---|
| 87 | + if (IS_ERR(clock)) { |
---|
| 88 | + /* Only some SoCs have a separate interface clock */ |
---|
| 89 | + if (PTR_ERR(clock) == -EINVAL && !strncmp("ick", name, 3)) |
---|
| 90 | + return; |
---|
| 91 | + |
---|
| 92 | + pr_warn("%s: could not get clock %s %li\n", |
---|
| 93 | + __func__, name, PTR_ERR(clock)); |
---|
| 94 | + return; |
---|
| 95 | + } |
---|
| 96 | + |
---|
| 97 | + error = clk_prepare_enable(clock); |
---|
| 98 | + if (error) { |
---|
| 99 | + pr_warn("%s: could not enable %s: %i\n", |
---|
| 100 | + __func__, name, error); |
---|
| 101 | + return; |
---|
| 102 | + } |
---|
| 103 | +} |
---|
| 104 | + |
---|
| 105 | +static void __init ti_32k_timer_module_init(struct device_node *np, |
---|
| 106 | + void __iomem *base) |
---|
| 107 | +{ |
---|
| 108 | + void __iomem *sysc = base + 4; |
---|
| 109 | + |
---|
| 110 | + if (!of_device_is_compatible(np->parent, "ti,sysc")) |
---|
| 111 | + return; |
---|
| 112 | + |
---|
| 113 | + ti_32k_timer_enable_clock(np, "fck"); |
---|
| 114 | + ti_32k_timer_enable_clock(np, "ick"); |
---|
| 115 | + |
---|
| 116 | + /* |
---|
| 117 | + * Force idle module as wkup domain is active with MPU. |
---|
| 118 | + * No need to tag the module disabled for ti-sysc probe. |
---|
| 119 | + */ |
---|
| 120 | + writel_relaxed(0, sysc); |
---|
| 121 | +} |
---|
| 122 | + |
---|
90 | 123 | static int __init ti_32k_timer_init(struct device_node *np) |
---|
91 | 124 | { |
---|
92 | 125 | int ret; |
---|
.. | .. |
---|
101 | 134 | ti_32k_timer.cs.flags |= CLOCK_SOURCE_SUSPEND_NONSTOP; |
---|
102 | 135 | |
---|
103 | 136 | ti_32k_timer.counter = ti_32k_timer.base; |
---|
| 137 | + ti_32k_timer_module_init(np, ti_32k_timer.base); |
---|
104 | 138 | |
---|
105 | 139 | /* |
---|
106 | 140 | * 32k sync Counter IP register offsets vary between the highlander |
---|
.. | .. |
---|
115 | 149 | else |
---|
116 | 150 | ti_32k_timer.counter += OMAP2_32KSYNCNT_CR_OFF_LOW; |
---|
117 | 151 | |
---|
| 152 | + pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n"); |
---|
| 153 | + |
---|
118 | 154 | ret = clocksource_register_hz(&ti_32k_timer.cs, 32768); |
---|
119 | 155 | if (ret) { |
---|
120 | 156 | pr_err("32k_counter: can't register clocksource\n"); |
---|
.. | .. |
---|
122 | 158 | } |
---|
123 | 159 | |
---|
124 | 160 | sched_clock_register(omap_32k_read_sched_clock, 32, 32768); |
---|
125 | | - pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n"); |
---|
126 | 161 | |
---|
127 | 162 | return 0; |
---|
128 | 163 | } |
---|