Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'timers-core-2020-06-02' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull timer updates from Thomas Gleixner:
"The truly boring timer and clocksource updates for 5.8:

- Not a single new clocksource or clockevent driver!

- Device tree updates for various chips

- Fixes and improvements and cleanups all over the place"

* tag 'timers-core-2020-06-02' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (27 commits)
dt-bindings: timer: Add renesas,em-sti bindings
clocksource/drivers/timer-versatile: Clear OF_POPULATED flag
clocksource: mips-gic-timer: Mark GIC timer as unstable if ref clock changes
clocksource: mips-gic-timer: Register as sched_clock
clocksource: dw_apb_timer_of: Fix missing clockevent timers
clocksource: dw_apb_timer: Affiliate of-based timer with any CPU
clocksource: dw_apb_timer: Make CPU-affiliation being optional
dt-bindings: timer: Move snps,dw-apb-timer DT schema from rtc
dt-bindings: rtc: Convert snps,dw-apb-timer to DT schema
clocksource/drivers/timer-ti-dm: Do one override clock parent in prepare()
clocksource/drivers/timer-ti-dm: Fix spelling mistake "detectt" -> "detect"
clocksource/drivers/timer-ti-dm: Fix warning for set but not used
clocksource/drivers/timer-ti-dm: Add clockevent and clocksource support
clocksource/drivers/timer-ti-32k: Add support for initializing directly
drivers/clocksource/arm_arch_timer: Remove duplicate error message
clocksource/drivers/arc_timer: Remove duplicate error message
clocksource/drivers/rda: drop redundant Kconfig dependency
clocksource/drivers/timer-ti-dm: Fix warning for set but not used
clocksource/drivers/timer-ti-dm: Add clockevent and clocksource support
clocksource/drivers/timer-ti-32k: Add support for initializing directly
...

+992 -75
-32
Documentation/devicetree/bindings/rtc/dw-apb.txt
··· 1 - * Designware APB timer 2 - 3 - Required properties: 4 - - compatible: One of: 5 - "snps,dw-apb-timer" 6 - "snps,dw-apb-timer-sp" <DEPRECATED> 7 - "snps,dw-apb-timer-osc" <DEPRECATED> 8 - - reg: physical base address of the controller and length of memory mapped 9 - region. 10 - - interrupts: IRQ line for the timer. 11 - - either clocks+clock-names or clock-frequency properties 12 - 13 - Optional properties: 14 - - clocks : list of clock specifiers, corresponding to entries in 15 - the clock-names property; 16 - - clock-names : should contain "timer" and "pclk" entries, matching entries 17 - in the clocks property. 18 - - clock-frequency: The frequency in HZ of the timer. 19 - - clock-freq: For backwards compatibility with picoxcell 20 - 21 - If using the clock specifiers, the pclk clock is optional, as not all 22 - systems may use one. 23 - 24 - 25 - Example: 26 - timer@ffe00000 { 27 - compatible = "snps,dw-apb-timer"; 28 - interrupts = <0 170 4>; 29 - reg = <0xffe00000 0x1000>; 30 - clocks = <&timer_clk>, <&timer_pclk>; 31 - clock-names = "timer", "pclk"; 32 - };
+46
Documentation/devicetree/bindings/timer/renesas,em-sti.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/timer/renesas,em-sti.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Renesas EMMA Mobile System Timer 8 + 9 + maintainers: 10 + - Magnus Damm <magnus.damm@gmail.com> 11 + 12 + properties: 13 + compatible: 14 + const: renesas,em-sti 15 + 16 + reg: 17 + maxItems: 1 18 + 19 + interrupts: 20 + maxItems: 1 21 + 22 + clocks: 23 + maxItems: 1 24 + 25 + clock-names: 26 + const: sclk 27 + 28 + required: 29 + - compatible 30 + - reg 31 + - interrupts 32 + - clocks 33 + - clock-names 34 + 35 + additionalProperties: false 36 + 37 + examples: 38 + - | 39 + #include <dt-bindings/interrupt-controller/arm-gic.h> 40 + timer@e0180000 { 41 + compatible = "renesas,em-sti"; 42 + reg = <0xe0180000 0x54>; 43 + interrupts = <GIC_SPI 125 IRQ_TYPE_LEVEL_HIGH>; 44 + clocks = <&sti_sclk>; 45 + clock-names = "sclk"; 46 + };
+88
Documentation/devicetree/bindings/timer/snps,dw-apb-timer.yaml
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/timer/snps,dw-apb-timer.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Synopsys DesignWare APB Timer 8 + 9 + maintainers: 10 + - Daniel Lezcano <daniel.lezcano@linaro.org> 11 + 12 + properties: 13 + compatible: 14 + oneOf: 15 + - const: snps,dw-apb-timer 16 + - enum: 17 + - snps,dw-apb-timer-sp 18 + - snps,dw-apb-timer-osc 19 + deprecated: true 20 + 21 + reg: 22 + maxItems: 1 23 + 24 + interrupts: 25 + maxItems: 1 26 + 27 + clocks: 28 + minItems: 1 29 + items: 30 + - description: Timer ticks reference clock source 31 + - description: APB interface clock source 32 + 33 + clock-names: 34 + minItems: 1 35 + items: 36 + - const: timer 37 + - const: pclk 38 + 39 + clock-frequency: true 40 + 41 + clock-freq: 42 + $ref: "/schemas/types.yaml#/definitions/uint32" 43 + description: | 44 + Has the same meaning as the 'clock-frequency' property - timer clock 45 + frequency in HZ, but is defined only for the backwards compatibility 46 + with the picoxcell platform. 47 + 48 + unevaluatedProperties: false 49 + 50 + required: 51 + - compatible 52 + - reg 53 + - interrupts 54 + 55 + oneOf: 56 + - required: 57 + - clocks 58 + - clock-names 59 + - required: 60 + - clock-frequency 61 + - required: 62 + - clock-freq 63 + 64 + examples: 65 + - | 66 + timer@ffe00000 { 67 + compatible = "snps,dw-apb-timer"; 68 + interrupts = <0 170 4>; 69 + reg = <0xffe00000 0x1000>; 70 + clocks = <&timer_clk>, <&timer_pclk>; 71 + clock-names = "timer", "pclk"; 72 + }; 73 + - | 74 + timer@ffe00000 { 75 + compatible = "snps,dw-apb-timer"; 76 + interrupts = <0 170 4>; 77 + reg = <0xffe00000 0x1000>; 78 + clocks = <&timer_clk>; 79 + clock-names = "timer"; 80 + }; 81 + - | 82 + timer@ffe00000 { 83 + compatible = "snps,dw-apb-timer"; 84 + interrupts = <0 170 4>; 85 + reg = <0xffe00000 0x1000>; 86 + clock-frequency = <25000000>; 87 + }; 88 + ...
+1
arch/arm/boot/dts/am335x-guardian.dts
··· 105 105 ti,timers = <&timer7>; 106 106 pinctrl-names = "default"; 107 107 pinctrl-0 = <&dmtimer7_pins>; 108 + ti,clock-source = <0x01>; 108 109 }; 109 110 110 111 vmmcsd_fixed: regulator-3v3 {
+1
arch/arm/boot/dts/am3517-evm.dts
··· 156 156 pinctrl-0 = <&pwm_pins>; 157 157 ti,timers = <&timer11>; 158 158 #pwm-cells = <3>; 159 + ti,clock-source = <0x01>; 159 160 }; 160 161 161 162 /* HS USB Host PHY on PORT 1 */
+1
arch/arm/boot/dts/logicpd-torpedo-baseboard.dtsi
··· 65 65 pinctrl-0 = <&pwm_pins>; 66 66 ti,timers = <&timer10>; 67 67 #pwm-cells = <3>; 68 + ti,clock-source = <0x01>; 68 69 }; 69 70 70 71 };
+1
arch/arm/boot/dts/omap3-gta04.dtsi
··· 150 150 compatible = "ti,omap-dmtimer-pwm"; 151 151 ti,timers = <&timer11>; 152 152 #pwm-cells = <3>; 153 + ti,clock-source = <0x01>; 153 154 }; 154 155 155 156 hsusb2_phy: hsusb2_phy {
+4 -4
drivers/clocksource/Kconfig
··· 120 120 121 121 config RDA_TIMER 122 122 bool "RDA timer driver" if COMPILE_TEST 123 - depends on GENERIC_CLOCKEVENTS 124 123 select CLKSRC_MMIO 125 124 select TIMER_OF 126 125 help ··· 561 562 bool "ARM Versatile (Express) reference platforms clock source" if COMPILE_TEST 562 563 depends on GENERIC_SCHED_CLOCK && !ARCH_USES_GETTIMEOFFSET 563 564 select TIMER_OF 564 - default y if MFD_VEXPRESS_SYSREG 565 + default y if (ARCH_VEXPRESS || ARCH_VERSATILE) && ARM 565 566 help 566 567 This option enables clock source based on free running 567 568 counter available in the "System Registers" block of 568 - ARM Versatile, RealView and Versatile Express reference 569 - platforms. 569 + ARM Versatile and Versatile Express reference platforms. 570 570 571 571 config CLKSRC_MIPS_GIC 572 572 bool 573 573 depends on MIPS_GIC 574 + select CLOCKSOURCE_WATCHDOG 574 575 select TIMER_OF 575 576 576 577 config CLKSRC_TANGO_XTAL ··· 708 709 bool "Microchip PIT64B support" 709 710 depends on OF || COMPILE_TEST 710 711 select CLKSRC_MMIO 712 + select TIMER_OF 711 713 help 712 714 This option enables Microchip PIT64B timer for Atmel 713 715 based system. It supports the oneshot, the periodic
+1
drivers/clocksource/Makefile
··· 18 18 obj-$(CONFIG_DAVINCI_TIMER) += timer-davinci.o 19 19 obj-$(CONFIG_DIGICOLOR_TIMER) += timer-digicolor.o 20 20 obj-$(CONFIG_OMAP_DM_TIMER) += timer-ti-dm.o 21 + obj-$(CONFIG_OMAP_DM_TIMER) += timer-ti-dm-systimer.o 21 22 obj-$(CONFIG_DW_APB_TIMER) += dw_apb_timer.o 22 23 obj-$(CONFIG_DW_APB_TIMER_OF) += dw_apb_timer_of.o 23 24 obj-$(CONFIG_FTTMR010_TIMER) += timer-fttmr010.o
+1 -3
drivers/clocksource/arc_timer.c
··· 334 334 } 335 335 336 336 ret = arc_get_timer_clk(node); 337 - if (ret) { 338 - pr_err("clockevent: missing clk\n"); 337 + if (ret) 339 338 return ret; 340 - } 341 339 342 340 /* Needs apriori irq_set_percpu_devid() done in intc map function */ 343 341 ret = request_percpu_irq(arc_timer_irq, timer_irq_handler,
+1 -3
drivers/clocksource/arm_arch_timer.c
··· 1588 1588 arch_timers_present |= ARCH_TIMER_TYPE_CP15; 1589 1589 1590 1590 ret = acpi_gtdt_init(table, &platform_timer_count); 1591 - if (ret) { 1592 - pr_err("Failed to init GTDT table.\n"); 1591 + if (ret) 1593 1592 return ret; 1594 - } 1595 1593 1596 1594 arch_timer_ppi[ARCH_TIMER_PHYS_NONSECURE_PPI] = 1597 1595 acpi_gtdt_map_ppi(ARCH_TIMER_PHYS_NONSECURE_PPI);
+3 -2
drivers/clocksource/dw_apb_timer.c
··· 222 222 /** 223 223 * dw_apb_clockevent_init() - use an APB timer as a clock_event_device 224 224 * 225 - * @cpu: The CPU the events will be targeted at. 225 + * @cpu: The CPU the events will be targeted at or -1 if CPU affiliation 226 + * isn't required. 226 227 * @name: The name used for the timer and the IRQ for it. 227 228 * @rating: The rating to give the timer. 228 229 * @base: I/O base for the timer registers. ··· 258 257 dw_ced->ced.max_delta_ticks = 0x7fffffff; 259 258 dw_ced->ced.min_delta_ns = clockevent_delta2ns(5000, &dw_ced->ced); 260 259 dw_ced->ced.min_delta_ticks = 5000; 261 - dw_ced->ced.cpumask = cpumask_of(cpu); 260 + dw_ced->ced.cpumask = cpu < 0 ? cpu_possible_mask : cpumask_of(cpu); 262 261 dw_ced->ced.features = CLOCK_EVT_FEAT_PERIODIC | 263 262 CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_DYNIRQ; 264 263 dw_ced->ced.set_state_shutdown = apbt_shutdown;
+3 -5
drivers/clocksource/dw_apb_timer_of.c
··· 73 73 74 74 timer_get_base_and_rate(event_timer, &iobase, &rate); 75 75 76 - ced = dw_apb_clockevent_init(0, event_timer->name, 300, iobase, irq, 76 + ced = dw_apb_clockevent_init(-1, event_timer->name, 300, iobase, irq, 77 77 rate); 78 78 if (!ced) 79 79 panic("Unable to initialise clockevent device"); ··· 147 147 static int __init dw_apb_timer_init(struct device_node *timer) 148 148 { 149 149 switch (num_called) { 150 - case 0: 151 - pr_debug("%s: found clockevent timer\n", __func__); 152 - add_clockevent(timer); 153 - break; 154 150 case 1: 155 151 pr_debug("%s: found clocksource timer\n", __func__); 156 152 add_clocksource(timer); ··· 157 161 #endif 158 162 break; 159 163 default: 164 + pr_debug("%s: found clockevent timer\n", __func__); 165 + add_clockevent(timer); 160 166 break; 161 167 } 162 168
+45 -5
drivers/clocksource/mips-gic-timer.c
··· 16 16 #include <linux/notifier.h> 17 17 #include <linux/of_irq.h> 18 18 #include <linux/percpu.h> 19 + #include <linux/sched_clock.h> 19 20 #include <linux/smp.h> 20 21 #include <linux/time.h> 21 22 #include <asm/mips-cps.h> ··· 24 23 static DEFINE_PER_CPU(struct clock_event_device, gic_clockevent_device); 25 24 static int gic_timer_irq; 26 25 static unsigned int gic_frequency; 26 + static bool __read_mostly gic_clock_unstable; 27 27 28 - static u64 notrace gic_read_count(void) 28 + static void gic_clocksource_unstable(char *reason); 29 + 30 + static u64 notrace gic_read_count_2x32(void) 29 31 { 30 32 unsigned int hi, hi2, lo; 31 - 32 - if (mips_cm_is64) 33 - return read_gic_counter(); 34 33 35 34 do { 36 35 hi = read_gic_counter_32h(); ··· 39 38 } while (hi2 != hi); 40 39 41 40 return (((u64) hi) << 32) + lo; 41 + } 42 + 43 + static u64 notrace gic_read_count_64(void) 44 + { 45 + return read_gic_counter(); 46 + } 47 + 48 + static u64 notrace gic_read_count(void) 49 + { 50 + if (mips_cm_is64) 51 + return gic_read_count_64(); 52 + 53 + return gic_read_count_2x32(); 42 54 } 43 55 44 56 static int gic_next_event(unsigned long delta, struct clock_event_device *evt) ··· 128 114 { 129 115 struct clk_notifier_data *cnd = data; 130 116 131 - if (action == POST_RATE_CHANGE) 117 + if (action == POST_RATE_CHANGE) { 118 + gic_clocksource_unstable("ref clock rate change"); 132 119 on_each_cpu(gic_update_frequency, (void *)cnd->new_rate, 1); 120 + } 133 121 134 122 return NOTIFY_OK; 135 123 } ··· 176 160 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 177 161 .vdso_clock_mode = VDSO_CLOCKMODE_GIC, 178 162 }; 163 + 164 + static void gic_clocksource_unstable(char *reason) 165 + { 166 + if (gic_clock_unstable) 167 + return; 168 + 169 + gic_clock_unstable = true; 170 + 171 + pr_info("GIC timer is unstable due to %s\n", reason); 172 + 173 + clocksource_mark_unstable(&gic_clocksource); 174 + } 179 175 180 176 static int __init __gic_clocksource_init(void) 181 177 { ··· 255 227 256 228 /* And finally start the counter */ 257 229 clear_gic_config(GIC_CONFIG_COUNTSTOP); 230 + 231 + /* 232 + * It's safe to use the MIPS GIC timer as a sched clock source only if 233 + * its ticks are stable, which is true on either the platforms with 234 + * stable CPU frequency or on the platforms with CM3 and CPU frequency 235 + * change performed by the CPC core clocks divider. 236 + */ 237 + if (mips_cm_revision() >= CM_REV_CM3 || !IS_ENABLED(CONFIG_CPU_FREQ)) { 238 + sched_clock_register(mips_cm_is64 ? 239 + gic_read_count_64 : gic_read_count_2x32, 240 + 64, gic_frequency); 241 + } 258 242 259 243 return 0; 260 244 }
+1 -2
drivers/clocksource/timer-atmel-st.c
··· 139 139 clkevt32k_next_event(unsigned long delta, struct clock_event_device *dev) 140 140 { 141 141 u32 alm; 142 - int status = 0; 143 142 unsigned int val; 144 143 145 144 BUG_ON(delta < 2); ··· 162 163 alm += delta; 163 164 regmap_write(regmap_st, AT91_ST_RTAR, alm); 164 165 165 - return status; 166 + return 0; 166 167 } 167 168 168 169 static struct clock_event_device clkevt = {
+11 -13
drivers/clocksource/timer-davinci.c
··· 18 18 #include <clocksource/timer-davinci.h> 19 19 20 20 #undef pr_fmt 21 - #define pr_fmt(fmt) "%s: " fmt "\n", __func__ 21 + #define pr_fmt(fmt) "%s: " fmt, __func__ 22 22 23 23 #define DAVINCI_TIMER_REG_TIM12 0x10 24 24 #define DAVINCI_TIMER_REG_TIM34 0x14 ··· 250 250 251 251 rv = clk_prepare_enable(clk); 252 252 if (rv) { 253 - pr_err("Unable to prepare and enable the timer clock"); 253 + pr_err("Unable to prepare and enable the timer clock\n"); 254 254 return rv; 255 255 } 256 256 257 257 if (!request_mem_region(timer_cfg->reg.start, 258 258 resource_size(&timer_cfg->reg), 259 259 "davinci-timer")) { 260 - pr_err("Unable to request memory region"); 260 + pr_err("Unable to request memory region\n"); 261 261 return -EBUSY; 262 262 } 263 263 264 264 base = ioremap(timer_cfg->reg.start, resource_size(&timer_cfg->reg)); 265 265 if (!base) { 266 - pr_err("Unable to map the register range"); 266 + pr_err("Unable to map the register range\n"); 267 267 return -ENOMEM; 268 268 } 269 269 270 270 davinci_timer_init(base); 271 271 tick_rate = clk_get_rate(clk); 272 272 273 - clockevent = kzalloc(sizeof(*clockevent), GFP_KERNEL | __GFP_NOFAIL); 274 - if (!clockevent) { 275 - pr_err("Error allocating memory for clockevent data"); 273 + clockevent = kzalloc(sizeof(*clockevent), GFP_KERNEL); 274 + if (!clockevent) 276 275 return -ENOMEM; 277 - } 278 276 279 277 clockevent->dev.name = "tim12"; 280 278 clockevent->dev.features = CLOCK_EVT_FEAT_ONESHOT; ··· 296 298 davinci_timer_irq_timer, IRQF_TIMER, 297 299 "clockevent/tim12", clockevent); 298 300 if (rv) { 299 - pr_err("Unable to request the clockevent interrupt"); 301 + pr_err("Unable to request the clockevent interrupt\n"); 300 302 return rv; 301 303 } 302 304 ··· 323 325 324 326 rv = clocksource_register_hz(&davinci_clocksource.dev, tick_rate); 325 327 if (rv) { 326 - pr_err("Unable to register clocksource"); 328 + pr_err("Unable to register clocksource\n"); 327 329 return rv; 328 330 } 329 331 ··· 341 343 342 344 rv = of_address_to_resource(np, 0, &timer_cfg.reg); 343 345 if (rv) { 344 - pr_err("Unable to get the register range for timer"); 346 + pr_err("Unable to get the register range for timer\n"); 345 347 return rv; 346 348 } 347 349 348 350 rv = of_irq_to_resource_table(np, timer_cfg.irq, 349 351 DAVINCI_TIMER_NUM_IRQS); 350 352 if (rv != DAVINCI_TIMER_NUM_IRQS) { 351 - pr_err("Unable to get the interrupts for timer"); 353 + pr_err("Unable to get the interrupts for timer\n"); 352 354 return rv; 353 355 } 354 356 355 357 clk = of_clk_get(np, 0); 356 358 if (IS_ERR(clk)) { 357 - pr_err("Unable to get the timer clock"); 359 + pr_err("Unable to get the timer clock\n"); 358 360 return PTR_ERR(clk); 359 361 } 360 362
+6 -2
drivers/clocksource/timer-imx-tpm.c
··· 61 61 writel(TPM_STATUS_CH0F, timer_base + TPM_STATUS); 62 62 } 63 63 64 - static struct delay_timer tpm_delay_timer; 65 - 66 64 static inline unsigned long tpm_read_counter(void) 67 65 { 68 66 return readl(timer_base + TPM_CNT); 69 67 } 70 68 69 + #if defined(CONFIG_ARM) 70 + static struct delay_timer tpm_delay_timer; 71 + 71 72 static unsigned long tpm_read_current_timer(void) 72 73 { 73 74 return tpm_read_counter(); 74 75 } 76 + #endif 75 77 76 78 static u64 notrace tpm_read_sched_clock(void) 77 79 { ··· 146 144 147 145 static int __init tpm_clocksource_init(void) 148 146 { 147 + #if defined(CONFIG_ARM) 149 148 tpm_delay_timer.read_current_timer = &tpm_read_current_timer; 150 149 tpm_delay_timer.freq = timer_of_rate(&to_tpm) >> 3; 151 150 register_current_timer_delay(&tpm_delay_timer); 151 + #endif 152 152 153 153 sched_clock_register(tpm_read_sched_clock, counter_width, 154 154 timer_of_rate(&to_tpm) >> 3);
+47 -1
drivers/clocksource/timer-ti-32k.c
··· 24 24 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com 25 25 */ 26 26 27 + #include <linux/clk.h> 27 28 #include <linux/init.h> 28 29 #include <linux/time.h> 29 30 #include <linux/sched_clock.h> ··· 77 76 return ti_32k_read_cycles(&ti_32k_timer.cs); 78 77 } 79 78 79 + static void __init ti_32k_timer_enable_clock(struct device_node *np, 80 + const char *name) 81 + { 82 + struct clk *clock; 83 + int error; 84 + 85 + clock = of_clk_get_by_name(np->parent, name); 86 + if (IS_ERR(clock)) { 87 + /* Only some SoCs have a separate interface clock */ 88 + if (PTR_ERR(clock) == -EINVAL && !strncmp("ick", name, 3)) 89 + return; 90 + 91 + pr_warn("%s: could not get clock %s %li\n", 92 + __func__, name, PTR_ERR(clock)); 93 + return; 94 + } 95 + 96 + error = clk_prepare_enable(clock); 97 + if (error) { 98 + pr_warn("%s: could not enable %s: %i\n", 99 + __func__, name, error); 100 + return; 101 + } 102 + } 103 + 104 + static void __init ti_32k_timer_module_init(struct device_node *np, 105 + void __iomem *base) 106 + { 107 + void __iomem *sysc = base + 4; 108 + 109 + if (!of_device_is_compatible(np->parent, "ti,sysc")) 110 + return; 111 + 112 + ti_32k_timer_enable_clock(np, "fck"); 113 + ti_32k_timer_enable_clock(np, "ick"); 114 + 115 + /* 116 + * Force idle module as wkup domain is active with MPU. 117 + * No need to tag the module disabled for ti-sysc probe. 118 + */ 119 + writel_relaxed(0, sysc); 120 + } 121 + 80 122 static int __init ti_32k_timer_init(struct device_node *np) 81 123 { 82 124 int ret; ··· 134 90 ti_32k_timer.cs.flags |= CLOCK_SOURCE_SUSPEND_NONSTOP; 135 91 136 92 ti_32k_timer.counter = ti_32k_timer.base; 93 + ti_32k_timer_module_init(np, ti_32k_timer.base); 137 94 138 95 /* 139 96 * 32k sync Counter IP register offsets vary between the highlander ··· 149 104 else 150 105 ti_32k_timer.counter += OMAP2_32KSYNCNT_CR_OFF_LOW; 151 106 107 + pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n"); 108 + 152 109 ret = clocksource_register_hz(&ti_32k_timer.cs, 32768); 153 110 if (ret) { 154 111 pr_err("32k_counter: can't register clocksource\n"); ··· 158 111 } 159 112 160 113 sched_clock_register(omap_32k_read_sched_clock, 32, 32768); 161 - pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n"); 162 114 163 115 return 0; 164 116 }
+727
drivers/clocksource/timer-ti-dm-systimer.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + #include <linux/clk.h> 3 + #include <linux/clocksource.h> 4 + #include <linux/clockchips.h> 5 + #include <linux/interrupt.h> 6 + #include <linux/io.h> 7 + #include <linux/iopoll.h> 8 + #include <linux/err.h> 9 + #include <linux/of.h> 10 + #include <linux/of_address.h> 11 + #include <linux/of_irq.h> 12 + #include <linux/sched_clock.h> 13 + 14 + #include <linux/clk/clk-conf.h> 15 + 16 + #include <clocksource/timer-ti-dm.h> 17 + #include <dt-bindings/bus/ti-sysc.h> 18 + 19 + /* For type1, set SYSC_OMAP2_CLOCKACTIVITY for fck off on idle, l4 clock on */ 20 + #define DMTIMER_TYPE1_ENABLE ((1 << 9) | (SYSC_IDLE_SMART << 3) | \ 21 + SYSC_OMAP2_ENAWAKEUP | SYSC_OMAP2_AUTOIDLE) 22 + 23 + #define DMTIMER_TYPE2_ENABLE (SYSC_IDLE_SMART_WKUP << 2) 24 + #define DMTIMER_RESET_WAIT 100000 25 + 26 + #define DMTIMER_INST_DONT_CARE ~0U 27 + 28 + static int counter_32k; 29 + static u32 clocksource; 30 + static u32 clockevent; 31 + 32 + /* 33 + * Subset of the timer registers we use. Note that the register offsets 34 + * depend on the timer revision detected. 35 + */ 36 + struct dmtimer_systimer { 37 + void __iomem *base; 38 + u8 sysc; 39 + u8 irq_stat; 40 + u8 irq_ena; 41 + u8 pend; 42 + u8 load; 43 + u8 counter; 44 + u8 ctrl; 45 + u8 wakeup; 46 + u8 ifctrl; 47 + unsigned long rate; 48 + }; 49 + 50 + struct dmtimer_clockevent { 51 + struct clock_event_device dev; 52 + struct dmtimer_systimer t; 53 + u32 period; 54 + }; 55 + 56 + struct dmtimer_clocksource { 57 + struct clocksource dev; 58 + struct dmtimer_systimer t; 59 + unsigned int loadval; 60 + }; 61 + 62 + /* Assumes v1 ip if bits [31:16] are zero */ 63 + static bool dmtimer_systimer_revision1(struct dmtimer_systimer *t) 64 + { 65 + u32 tidr = readl_relaxed(t->base); 66 + 67 + return !(tidr >> 16); 68 + } 69 + 70 + static int __init dmtimer_systimer_type1_reset(struct dmtimer_systimer *t) 71 + { 72 + void __iomem *syss = t->base + OMAP_TIMER_V1_SYS_STAT_OFFSET; 73 + int ret; 74 + u32 l; 75 + 76 + writel_relaxed(BIT(1) | BIT(2), t->base + t->ifctrl); 77 + ret = readl_poll_timeout_atomic(syss, l, l & BIT(0), 100, 78 + DMTIMER_RESET_WAIT); 79 + 80 + return ret; 81 + } 82 + 83 + /* Note we must use io_base instead of func_base for type2 OCP regs */ 84 + static int __init dmtimer_systimer_type2_reset(struct dmtimer_systimer *t) 85 + { 86 + void __iomem *sysc = t->base + t->sysc; 87 + u32 l; 88 + 89 + l = readl_relaxed(sysc); 90 + l |= BIT(0); 91 + writel_relaxed(l, sysc); 92 + 93 + return readl_poll_timeout_atomic(sysc, l, !(l & BIT(0)), 100, 94 + DMTIMER_RESET_WAIT); 95 + } 96 + 97 + static int __init dmtimer_systimer_reset(struct dmtimer_systimer *t) 98 + { 99 + int ret; 100 + 101 + if (dmtimer_systimer_revision1(t)) 102 + ret = dmtimer_systimer_type1_reset(t); 103 + else 104 + ret = dmtimer_systimer_type2_reset(t); 105 + if (ret < 0) { 106 + pr_err("%s failed with %i\n", __func__, ret); 107 + 108 + return ret; 109 + } 110 + 111 + return 0; 112 + } 113 + 114 + static const struct of_device_id counter_match_table[] = { 115 + { .compatible = "ti,omap-counter32k" }, 116 + { /* Sentinel */ }, 117 + }; 118 + 119 + /* 120 + * Check if the SoC als has a usable working 32 KiHz counter. The 32 KiHz 121 + * counter is handled by timer-ti-32k, but we need to detect it as it 122 + * affects the preferred dmtimer system timer configuration. There is 123 + * typically no use for a dmtimer clocksource if the 32 KiHz counter is 124 + * present, except on am437x as described below. 125 + */ 126 + static void __init dmtimer_systimer_check_counter32k(void) 127 + { 128 + struct device_node *np; 129 + 130 + if (counter_32k) 131 + return; 132 + 133 + np = of_find_matching_node(NULL, counter_match_table); 134 + if (!np) { 135 + counter_32k = -ENODEV; 136 + 137 + return; 138 + } 139 + 140 + if (of_device_is_available(np)) 141 + counter_32k = 1; 142 + else 143 + counter_32k = -ENODEV; 144 + 145 + of_node_put(np); 146 + } 147 + 148 + static const struct of_device_id dmtimer_match_table[] = { 149 + { .compatible = "ti,omap2420-timer", }, 150 + { .compatible = "ti,omap3430-timer", }, 151 + { .compatible = "ti,omap4430-timer", }, 152 + { .compatible = "ti,omap5430-timer", }, 153 + { .compatible = "ti,am335x-timer", }, 154 + { .compatible = "ti,am335x-timer-1ms", }, 155 + { .compatible = "ti,dm814-timer", }, 156 + { .compatible = "ti,dm816-timer", }, 157 + { /* Sentinel */ }, 158 + }; 159 + 160 + /* 161 + * Checks that system timers are configured to not reset and idle during 162 + * the generic timer-ti-dm device driver probe. And that the system timer 163 + * source clocks are properly configured. Also, let's not hog any DSP and 164 + * PWM capable timers unnecessarily as system timers. 165 + */ 166 + static bool __init dmtimer_is_preferred(struct device_node *np) 167 + { 168 + if (!of_device_is_available(np)) 169 + return false; 170 + 171 + if (!of_property_read_bool(np->parent, 172 + "ti,no-reset-on-init")) 173 + return false; 174 + 175 + if (!of_property_read_bool(np->parent, "ti,no-idle")) 176 + return false; 177 + 178 + /* Secure gptimer12 is always clocked with a fixed source */ 179 + if (!of_property_read_bool(np, "ti,timer-secure")) { 180 + if (!of_property_read_bool(np, "assigned-clocks")) 181 + return false; 182 + 183 + if (!of_property_read_bool(np, "assigned-clock-parents")) 184 + return false; 185 + } 186 + 187 + if (of_property_read_bool(np, "ti,timer-dsp")) 188 + return false; 189 + 190 + if (of_property_read_bool(np, "ti,timer-pwm")) 191 + return false; 192 + 193 + return true; 194 + } 195 + 196 + /* 197 + * Finds the first available usable always-on timer, and assigns it to either 198 + * clockevent or clocksource depending if the counter_32k is available on the 199 + * SoC or not. 200 + * 201 + * Some omap3 boards with unreliable oscillator must not use the counter_32k 202 + * or dmtimer1 with 32 KiHz source. Additionally, the boards with unreliable 203 + * oscillator should really set counter_32k as disabled, and delete dmtimer1 204 + * ti,always-on property, but let's not count on it. For these quirky cases, 205 + * we prefer using the always-on secure dmtimer12 with the internal 32 KiHz 206 + * clock as the clocksource, and any available dmtimer as clockevent. 207 + * 208 + * For am437x, we are using am335x style dmtimer clocksource. It is unclear 209 + * if this quirk handling is really needed, but let's change it separately 210 + * based on testing as it might cause side effects. 211 + */ 212 + static void __init dmtimer_systimer_assign_alwon(void) 213 + { 214 + struct device_node *np; 215 + u32 pa = 0; 216 + bool quirk_unreliable_oscillator = false; 217 + 218 + /* Quirk unreliable 32 KiHz oscillator with incomplete dts */ 219 + if (of_machine_is_compatible("ti,omap3-beagle") || 220 + of_machine_is_compatible("timll,omap3-devkit8000")) { 221 + quirk_unreliable_oscillator = true; 222 + counter_32k = -ENODEV; 223 + } 224 + 225 + /* Quirk am437x using am335x style dmtimer clocksource */ 226 + if (of_machine_is_compatible("ti,am43")) 227 + counter_32k = -ENODEV; 228 + 229 + for_each_matching_node(np, dmtimer_match_table) { 230 + if (!dmtimer_is_preferred(np)) 231 + continue; 232 + 233 + if (of_property_read_bool(np, "ti,timer-alwon")) { 234 + const __be32 *addr; 235 + 236 + addr = of_get_address(np, 0, NULL, NULL); 237 + pa = of_translate_address(np, addr); 238 + if (pa) { 239 + /* Quirky omap3 boards must use dmtimer12 */ 240 + if (quirk_unreliable_oscillator && 241 + pa == 0x48318000) 242 + continue; 243 + 244 + of_node_put(np); 245 + break; 246 + } 247 + } 248 + } 249 + 250 + /* Usually no need for dmtimer clocksource if we have counter32 */ 251 + if (counter_32k >= 0) { 252 + clockevent = pa; 253 + clocksource = 0; 254 + } else { 255 + clocksource = pa; 256 + clockevent = DMTIMER_INST_DONT_CARE; 257 + } 258 + } 259 + 260 + /* Finds the first usable dmtimer, used for the don't care case */ 261 + static u32 __init dmtimer_systimer_find_first_available(void) 262 + { 263 + struct device_node *np; 264 + const __be32 *addr; 265 + u32 pa = 0; 266 + 267 + for_each_matching_node(np, dmtimer_match_table) { 268 + if (!dmtimer_is_preferred(np)) 269 + continue; 270 + 271 + addr = of_get_address(np, 0, NULL, NULL); 272 + pa = of_translate_address(np, addr); 273 + if (pa) { 274 + if (pa == clocksource || pa == clockevent) { 275 + pa = 0; 276 + continue; 277 + } 278 + 279 + of_node_put(np); 280 + break; 281 + } 282 + } 283 + 284 + return pa; 285 + } 286 + 287 + /* Selects the best clocksource and clockevent to use */ 288 + static void __init dmtimer_systimer_select_best(void) 289 + { 290 + dmtimer_systimer_check_counter32k(); 291 + dmtimer_systimer_assign_alwon(); 292 + 293 + if (clockevent == DMTIMER_INST_DONT_CARE) 294 + clockevent = dmtimer_systimer_find_first_available(); 295 + 296 + pr_debug("%s: counter_32k: %i clocksource: %08x clockevent: %08x\n", 297 + __func__, counter_32k, clocksource, clockevent); 298 + } 299 + 300 + /* Interface clocks are only available on some SoCs variants */ 301 + static int __init dmtimer_systimer_init_clock(struct device_node *np, 302 + const char *name, 303 + unsigned long *rate) 304 + { 305 + struct clk *clock; 306 + unsigned long r; 307 + int error; 308 + 309 + clock = of_clk_get_by_name(np, name); 310 + if ((PTR_ERR(clock) == -EINVAL) && !strncmp(name, "ick", 3)) 311 + return 0; 312 + else if (IS_ERR(clock)) 313 + return PTR_ERR(clock); 314 + 315 + error = clk_prepare_enable(clock); 316 + if (error) 317 + return error; 318 + 319 + r = clk_get_rate(clock); 320 + if (!r) 321 + return -ENODEV; 322 + 323 + *rate = r; 324 + 325 + return 0; 326 + } 327 + 328 + static void dmtimer_systimer_enable(struct dmtimer_systimer *t) 329 + { 330 + u32 val; 331 + 332 + if (dmtimer_systimer_revision1(t)) 333 + val = DMTIMER_TYPE1_ENABLE; 334 + else 335 + val = DMTIMER_TYPE2_ENABLE; 336 + 337 + writel_relaxed(val, t->base + t->sysc); 338 + } 339 + 340 + static void dmtimer_systimer_disable(struct dmtimer_systimer *t) 341 + { 342 + writel_relaxed(0, t->base + t->sysc); 343 + } 344 + 345 + static int __init dmtimer_systimer_setup(struct device_node *np, 346 + struct dmtimer_systimer *t) 347 + { 348 + unsigned long rate; 349 + u8 regbase; 350 + int error; 351 + 352 + if (!of_device_is_compatible(np->parent, "ti,sysc")) 353 + return -EINVAL; 354 + 355 + t->base = of_iomap(np, 0); 356 + if (!t->base) 357 + return -ENXIO; 358 + 359 + /* 360 + * Enable optional assigned-clock-parents configured at the timer 361 + * node level. For regular device drivers, this is done automatically 362 + * by bus related code such as platform_drv_probe(). 363 + */ 364 + error = of_clk_set_defaults(np, false); 365 + if (error < 0) 366 + pr_err("%s: clock source init failed: %i\n", __func__, error); 367 + 368 + /* For ti-sysc, we have timer clocks at the parent module level */ 369 + error = dmtimer_systimer_init_clock(np->parent, "fck", &rate); 370 + if (error) 371 + goto err_unmap; 372 + 373 + t->rate = rate; 374 + 375 + error = dmtimer_systimer_init_clock(np->parent, "ick", &rate); 376 + if (error) 377 + goto err_unmap; 378 + 379 + if (dmtimer_systimer_revision1(t)) { 380 + t->irq_stat = OMAP_TIMER_V1_STAT_OFFSET; 381 + t->irq_ena = OMAP_TIMER_V1_INT_EN_OFFSET; 382 + t->pend = _OMAP_TIMER_WRITE_PEND_OFFSET; 383 + regbase = 0; 384 + } else { 385 + t->irq_stat = OMAP_TIMER_V2_IRQSTATUS; 386 + t->irq_ena = OMAP_TIMER_V2_IRQENABLE_SET; 387 + regbase = OMAP_TIMER_V2_FUNC_OFFSET; 388 + t->pend = regbase + _OMAP_TIMER_WRITE_PEND_OFFSET; 389 + } 390 + 391 + t->sysc = OMAP_TIMER_OCP_CFG_OFFSET; 392 + t->load = regbase + _OMAP_TIMER_LOAD_OFFSET; 393 + t->counter = regbase + _OMAP_TIMER_COUNTER_OFFSET; 394 + t->ctrl = regbase + _OMAP_TIMER_CTRL_OFFSET; 395 + t->wakeup = regbase + _OMAP_TIMER_WAKEUP_EN_OFFSET; 396 + t->ifctrl = regbase + _OMAP_TIMER_IF_CTRL_OFFSET; 397 + 398 + dmtimer_systimer_enable(t); 399 + dmtimer_systimer_reset(t); 400 + pr_debug("dmtimer rev %08x sysc %08x\n", readl_relaxed(t->base), 401 + readl_relaxed(t->base + t->sysc)); 402 + 403 + return 0; 404 + 405 + err_unmap: 406 + iounmap(t->base); 407 + 408 + return error; 409 + } 410 + 411 + /* Clockevent */ 412 + static struct dmtimer_clockevent * 413 + to_dmtimer_clockevent(struct clock_event_device *clockevent) 414 + { 415 + return container_of(clockevent, struct dmtimer_clockevent, dev); 416 + } 417 + 418 + static irqreturn_t dmtimer_clockevent_interrupt(int irq, void *data) 419 + { 420 + struct dmtimer_clockevent *clkevt = data; 421 + struct dmtimer_systimer *t = &clkevt->t; 422 + 423 + writel_relaxed(OMAP_TIMER_INT_OVERFLOW, t->base + t->irq_stat); 424 + clkevt->dev.event_handler(&clkevt->dev); 425 + 426 + return IRQ_HANDLED; 427 + } 428 + 429 + static int dmtimer_set_next_event(unsigned long cycles, 430 + struct clock_event_device *evt) 431 + { 432 + struct dmtimer_clockevent *clkevt = to_dmtimer_clockevent(evt); 433 + struct dmtimer_systimer *t = &clkevt->t; 434 + void __iomem *pend = t->base + t->pend; 435 + 436 + writel_relaxed(0xffffffff - cycles, t->base + t->counter); 437 + while (readl_relaxed(pend) & WP_TCRR) 438 + cpu_relax(); 439 + 440 + writel_relaxed(OMAP_TIMER_CTRL_ST, t->base + t->ctrl); 441 + while (readl_relaxed(pend) & WP_TCLR) 442 + cpu_relax(); 443 + 444 + return 0; 445 + } 446 + 447 + static int dmtimer_clockevent_shutdown(struct clock_event_device *evt) 448 + { 449 + struct dmtimer_clockevent *clkevt = to_dmtimer_clockevent(evt); 450 + struct dmtimer_systimer *t = &clkevt->t; 451 + void __iomem *ctrl = t->base + t->ctrl; 452 + u32 l; 453 + 454 + l = readl_relaxed(ctrl); 455 + if (l & OMAP_TIMER_CTRL_ST) { 456 + l &= ~BIT(0); 457 + writel_relaxed(l, ctrl); 458 + /* Flush posted write */ 459 + l = readl_relaxed(ctrl); 460 + /* Wait for functional clock period x 3.5 */ 461 + udelay(3500000 / t->rate + 1); 462 + } 463 + writel_relaxed(OMAP_TIMER_INT_OVERFLOW, t->base + t->irq_stat); 464 + 465 + return 0; 466 + } 467 + 468 + static int dmtimer_set_periodic(struct clock_event_device *evt) 469 + { 470 + struct dmtimer_clockevent *clkevt = to_dmtimer_clockevent(evt); 471 + struct dmtimer_systimer *t = &clkevt->t; 472 + void __iomem *pend = t->base + t->pend; 473 + 474 + dmtimer_clockevent_shutdown(evt); 475 + 476 + /* Looks like we need to first set the load value separately */ 477 + writel_relaxed(clkevt->period, t->base + t->load); 478 + while (readl_relaxed(pend) & WP_TLDR) 479 + cpu_relax(); 480 + 481 + writel_relaxed(clkevt->period, t->base + t->counter); 482 + while (readl_relaxed(pend) & WP_TCRR) 483 + cpu_relax(); 484 + 485 + writel_relaxed(OMAP_TIMER_CTRL_AR | OMAP_TIMER_CTRL_ST, 486 + t->base + t->ctrl); 487 + while (readl_relaxed(pend) & WP_TCLR) 488 + cpu_relax(); 489 + 490 + return 0; 491 + } 492 + 493 + static void omap_clockevent_idle(struct clock_event_device *evt) 494 + { 495 + struct dmtimer_clockevent *clkevt = to_dmtimer_clockevent(evt); 496 + struct dmtimer_systimer *t = &clkevt->t; 497 + 498 + dmtimer_systimer_disable(t); 499 + } 500 + 501 + static void omap_clockevent_unidle(struct clock_event_device *evt) 502 + { 503 + struct dmtimer_clockevent *clkevt = to_dmtimer_clockevent(evt); 504 + struct dmtimer_systimer *t = &clkevt->t; 505 + 506 + dmtimer_systimer_enable(t); 507 + writel_relaxed(OMAP_TIMER_INT_OVERFLOW, t->base + t->irq_ena); 508 + writel_relaxed(OMAP_TIMER_INT_OVERFLOW, t->base + t->wakeup); 509 + } 510 + 511 + static int __init dmtimer_clockevent_init(struct device_node *np) 512 + { 513 + struct dmtimer_clockevent *clkevt; 514 + struct clock_event_device *dev; 515 + struct dmtimer_systimer *t; 516 + int error; 517 + 518 + clkevt = kzalloc(sizeof(*clkevt), GFP_KERNEL); 519 + if (!clkevt) 520 + return -ENOMEM; 521 + 522 + t = &clkevt->t; 523 + dev = &clkevt->dev; 524 + 525 + /* 526 + * We mostly use cpuidle_coupled with ARM local timers for runtime, 527 + * so there's probably no use for CLOCK_EVT_FEAT_DYNIRQ here. 528 + */ 529 + dev->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; 530 + dev->rating = 300; 531 + dev->set_next_event = dmtimer_set_next_event; 532 + dev->set_state_shutdown = dmtimer_clockevent_shutdown; 533 + dev->set_state_periodic = dmtimer_set_periodic; 534 + dev->set_state_oneshot = dmtimer_clockevent_shutdown; 535 + dev->tick_resume = dmtimer_clockevent_shutdown; 536 + dev->cpumask = cpu_possible_mask; 537 + 538 + dev->irq = irq_of_parse_and_map(np, 0); 539 + if (!dev->irq) { 540 + error = -ENXIO; 541 + goto err_out_free; 542 + } 543 + 544 + error = dmtimer_systimer_setup(np, &clkevt->t); 545 + if (error) 546 + goto err_out_free; 547 + 548 + clkevt->period = 0xffffffff - DIV_ROUND_CLOSEST(t->rate, HZ); 549 + 550 + /* 551 + * For clock-event timers we never read the timer counter and 552 + * so we are not impacted by errata i103 and i767. Therefore, 553 + * we can safely ignore this errata for clock-event timers. 554 + */ 555 + writel_relaxed(OMAP_TIMER_CTRL_POSTED, t->base + t->ifctrl); 556 + 557 + error = request_irq(dev->irq, dmtimer_clockevent_interrupt, 558 + IRQF_TIMER, "clockevent", clkevt); 559 + if (error) 560 + goto err_out_unmap; 561 + 562 + writel_relaxed(OMAP_TIMER_INT_OVERFLOW, t->base + t->irq_ena); 563 + writel_relaxed(OMAP_TIMER_INT_OVERFLOW, t->base + t->wakeup); 564 + 565 + pr_info("TI gptimer clockevent: %s%lu Hz at %pOF\n", 566 + of_find_property(np, "ti,timer-alwon", NULL) ? 567 + "always-on " : "", t->rate, np->parent); 568 + 569 + clockevents_config_and_register(dev, t->rate, 570 + 3, /* Timer internal resynch latency */ 571 + 0xffffffff); 572 + 573 + if (of_device_is_compatible(np, "ti,am33xx") || 574 + of_device_is_compatible(np, "ti,am43")) { 575 + dev->suspend = omap_clockevent_idle; 576 + dev->resume = omap_clockevent_unidle; 577 + } 578 + 579 + return 0; 580 + 581 + err_out_unmap: 582 + iounmap(t->base); 583 + 584 + err_out_free: 585 + kfree(clkevt); 586 + 587 + return error; 588 + } 589 + 590 + /* Clocksource */ 591 + static struct dmtimer_clocksource * 592 + to_dmtimer_clocksource(struct clocksource *cs) 593 + { 594 + return container_of(cs, struct dmtimer_clocksource, dev); 595 + } 596 + 597 + static u64 dmtimer_clocksource_read_cycles(struct clocksource *cs) 598 + { 599 + struct dmtimer_clocksource *clksrc = to_dmtimer_clocksource(cs); 600 + struct dmtimer_systimer *t = &clksrc->t; 601 + 602 + return (u64)readl_relaxed(t->base + t->counter); 603 + } 604 + 605 + static void __iomem *dmtimer_sched_clock_counter; 606 + 607 + static u64 notrace dmtimer_read_sched_clock(void) 608 + { 609 + return readl_relaxed(dmtimer_sched_clock_counter); 610 + } 611 + 612 + static void dmtimer_clocksource_suspend(struct clocksource *cs) 613 + { 614 + struct dmtimer_clocksource *clksrc = to_dmtimer_clocksource(cs); 615 + struct dmtimer_systimer *t = &clksrc->t; 616 + 617 + clksrc->loadval = readl_relaxed(t->base + t->counter); 618 + dmtimer_systimer_disable(t); 619 + } 620 + 621 + static void dmtimer_clocksource_resume(struct clocksource *cs) 622 + { 623 + struct dmtimer_clocksource *clksrc = to_dmtimer_clocksource(cs); 624 + struct dmtimer_systimer *t = &clksrc->t; 625 + 626 + dmtimer_systimer_enable(t); 627 + writel_relaxed(clksrc->loadval, t->base + t->counter); 628 + writel_relaxed(OMAP_TIMER_CTRL_ST | OMAP_TIMER_CTRL_AR, 629 + t->base + t->ctrl); 630 + } 631 + 632 + static int __init dmtimer_clocksource_init(struct device_node *np) 633 + { 634 + struct dmtimer_clocksource *clksrc; 635 + struct dmtimer_systimer *t; 636 + struct clocksource *dev; 637 + int error; 638 + 639 + clksrc = kzalloc(sizeof(*clksrc), GFP_KERNEL); 640 + if (!clksrc) 641 + return -ENOMEM; 642 + 643 + dev = &clksrc->dev; 644 + t = &clksrc->t; 645 + 646 + error = dmtimer_systimer_setup(np, t); 647 + if (error) 648 + goto err_out_free; 649 + 650 + dev->name = "dmtimer"; 651 + dev->rating = 300; 652 + dev->read = dmtimer_clocksource_read_cycles; 653 + dev->mask = CLOCKSOURCE_MASK(32); 654 + dev->flags = CLOCK_SOURCE_IS_CONTINUOUS; 655 + 656 + if (of_device_is_compatible(np, "ti,am33xx") || 657 + of_device_is_compatible(np, "ti,am43")) { 658 + dev->suspend = dmtimer_clocksource_suspend; 659 + dev->resume = dmtimer_clocksource_resume; 660 + } 661 + 662 + writel_relaxed(0, t->base + t->counter); 663 + writel_relaxed(OMAP_TIMER_CTRL_ST | OMAP_TIMER_CTRL_AR, 664 + t->base + t->ctrl); 665 + 666 + pr_info("TI gptimer clocksource: %s%pOF\n", 667 + of_find_property(np, "ti,timer-alwon", NULL) ? 668 + "always-on " : "", np->parent); 669 + 670 + if (!dmtimer_sched_clock_counter) { 671 + dmtimer_sched_clock_counter = t->base + t->counter; 672 + sched_clock_register(dmtimer_read_sched_clock, 32, t->rate); 673 + } 674 + 675 + if (clocksource_register_hz(dev, t->rate)) 676 + pr_err("Could not register clocksource %pOF\n", np); 677 + 678 + return 0; 679 + 680 + err_out_free: 681 + kfree(clksrc); 682 + 683 + return -ENODEV; 684 + } 685 + 686 + /* 687 + * To detect between a clocksource and clockevent, we assume the device tree 688 + * has no interrupts configured for a clocksource timer. 689 + */ 690 + static int __init dmtimer_systimer_init(struct device_node *np) 691 + { 692 + const __be32 *addr; 693 + u32 pa; 694 + 695 + /* One time init for the preferred timer configuration */ 696 + if (!clocksource && !clockevent) 697 + dmtimer_systimer_select_best(); 698 + 699 + if (!clocksource && !clockevent) { 700 + pr_err("%s: unable to detect system timers, update dtb?\n", 701 + __func__); 702 + 703 + return -EINVAL; 704 + } 705 + 706 + addr = of_get_address(np, 0, NULL, NULL); 707 + pa = of_translate_address(np, addr); 708 + if (!pa) 709 + return -EINVAL; 710 + 711 + if (counter_32k <= 0 && clocksource == pa) 712 + return dmtimer_clocksource_init(np); 713 + 714 + if (clockevent == pa) 715 + return dmtimer_clockevent_init(np); 716 + 717 + return 0; 718 + } 719 + 720 + TIMER_OF_DECLARE(systimer_omap2, "ti,omap2420-timer", dmtimer_systimer_init); 721 + TIMER_OF_DECLARE(systimer_omap3, "ti,omap3430-timer", dmtimer_systimer_init); 722 + TIMER_OF_DECLARE(systimer_omap4, "ti,omap4430-timer", dmtimer_systimer_init); 723 + TIMER_OF_DECLARE(systimer_omap5, "ti,omap5430-timer", dmtimer_systimer_init); 724 + TIMER_OF_DECLARE(systimer_am33x, "ti,am335x-timer", dmtimer_systimer_init); 725 + TIMER_OF_DECLARE(systimer_am3ms, "ti,am335x-timer-1ms", dmtimer_systimer_init); 726 + TIMER_OF_DECLARE(systimer_dm814, "ti,dm814-timer", dmtimer_systimer_init); 727 + TIMER_OF_DECLARE(systimer_dm816, "ti,dm816-timer", dmtimer_systimer_init);
+1 -3
drivers/clocksource/timer-ti-dm.c
··· 258 258 __omap_dm_timer_enable_posted(timer); 259 259 omap_dm_timer_disable(timer); 260 260 261 - rc = omap_dm_timer_set_source(timer, OMAP_TIMER_SRC_32_KHZ); 262 - 263 - return rc; 261 + return 0; 264 262 } 265 263 266 264 static inline u32 omap_dm_timer_reserved_systimer(int id)
+3
drivers/clocksource/timer-versatile.c
··· 6 6 7 7 #include <linux/clocksource.h> 8 8 #include <linux/io.h> 9 + #include <linux/of.h> 9 10 #include <linux/of_address.h> 10 11 #include <linux/sched_clock.h> 11 12 ··· 22 21 static int __init versatile_sched_clock_init(struct device_node *node) 23 22 { 24 23 void __iomem *base = of_iomap(node, 0); 24 + 25 + of_node_clear_flag(node, OF_POPULATED); 25 26 26 27 if (!base) 27 28 return -ENXIO;