hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/clocksource/timer-ti-32k.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /**
23 * timer-ti-32k.c - OMAP2 32k Timer Support
34 *
....@@ -20,21 +21,10 @@
2021 * Roughly modelled after the OMAP1 MPU timer code.
2122 * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
2223 *
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
3625 */
3726
27
+#include <linux/clk.h>
3828 #include <linux/init.h>
3929 #include <linux/time.h>
4030 #include <linux/sched_clock.h>
....@@ -87,6 +77,49 @@
8777 return ti_32k_read_cycles(&ti_32k_timer.cs);
8878 }
8979
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
+
90123 static int __init ti_32k_timer_init(struct device_node *np)
91124 {
92125 int ret;
....@@ -101,6 +134,7 @@
101134 ti_32k_timer.cs.flags |= CLOCK_SOURCE_SUSPEND_NONSTOP;
102135
103136 ti_32k_timer.counter = ti_32k_timer.base;
137
+ ti_32k_timer_module_init(np, ti_32k_timer.base);
104138
105139 /*
106140 * 32k sync Counter IP register offsets vary between the highlander
....@@ -115,6 +149,8 @@
115149 else
116150 ti_32k_timer.counter += OMAP2_32KSYNCNT_CR_OFF_LOW;
117151
152
+ pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n");
153
+
118154 ret = clocksource_register_hz(&ti_32k_timer.cs, 32768);
119155 if (ret) {
120156 pr_err("32k_counter: can't register clocksource\n");
....@@ -122,7 +158,6 @@
122158 }
123159
124160 sched_clock_register(omap_32k_read_sched_clock, 32, 32768);
125
- pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n");
126161
127162 return 0;
128163 }