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

Merge tag 'timers-v5.6' of https://git.linaro.org/people/daniel.lezcano/linux into timers/core

Pull clockevent updates from Daniel Lezcano:

- Some cleanups for the timer-of, use %p0F and the unique device name
(Geert Uytterhoeven)

- Use timer-of for the renesas-ostm and the device name to prevent
name collision in case of multiple timers (Geert Uytterhoeven)

- Check if there is an error after calling of_clk_get in asm9260
(Chuhong Yuan)

+79 -119
+1
drivers/clocksource/Kconfig
··· 528 528 config RENESAS_OSTM 529 529 bool "Renesas OSTM timer driver" if COMPILE_TEST 530 530 select CLKSRC_MMIO 531 + select TIMER_OF 531 532 help 532 533 Enables the support for the Renesas OSTM. 533 534
+4
drivers/clocksource/asm9260_timer.c
··· 194 194 } 195 195 196 196 clk = of_clk_get(np, 0); 197 + if (IS_ERR(clk)) { 198 + pr_err("Failed to get clk!\n"); 199 + return PTR_ERR(clk); 200 + } 197 201 198 202 ret = clk_prepare_enable(clk); 199 203 if (ret) {
+71 -116
drivers/clocksource/renesas-ostm.c
··· 6 6 * Copyright (C) 2017 Chris Brandt 7 7 */ 8 8 9 - #include <linux/of_address.h> 10 - #include <linux/of_irq.h> 11 9 #include <linux/clk.h> 12 10 #include <linux/clockchips.h> 13 11 #include <linux/interrupt.h> 14 12 #include <linux/sched_clock.h> 15 13 #include <linux/slab.h> 14 + 15 + #include "timer-of.h" 16 16 17 17 /* 18 18 * The OSTM contains independent channels. ··· 23 23 * The second (or more) channel probed will be set up as an interrupt 24 24 * driven clock event. 25 25 */ 26 - 27 - struct ostm_device { 28 - void __iomem *base; 29 - unsigned long ticks_per_jiffy; 30 - struct clock_event_device ced; 31 - }; 32 26 33 27 static void __iomem *system_clock; /* For sched_clock() */ 34 28 ··· 41 47 #define CTL_ONESHOT 0x02 42 48 #define CTL_FREERUN 0x02 43 49 44 - static struct ostm_device *ced_to_ostm(struct clock_event_device *ced) 50 + static void ostm_timer_stop(struct timer_of *to) 45 51 { 46 - return container_of(ced, struct ostm_device, ced); 47 - } 48 - 49 - static void ostm_timer_stop(struct ostm_device *ostm) 50 - { 51 - if (readb(ostm->base + OSTM_TE) & TE) { 52 - writeb(TT, ostm->base + OSTM_TT); 52 + if (readb(timer_of_base(to) + OSTM_TE) & TE) { 53 + writeb(TT, timer_of_base(to) + OSTM_TT); 53 54 54 55 /* 55 56 * Read back the register simply to confirm the write operation 56 57 * has completed since I/O writes can sometimes get queued by 57 58 * the bus architecture. 58 59 */ 59 - while (readb(ostm->base + OSTM_TE) & TE) 60 + while (readb(timer_of_base(to) + OSTM_TE) & TE) 60 61 ; 61 62 } 62 63 } 63 64 64 - static int __init ostm_init_clksrc(struct ostm_device *ostm, unsigned long rate) 65 + static int __init ostm_init_clksrc(struct timer_of *to) 65 66 { 66 - /* 67 - * irq not used (clock sources don't use interrupts) 68 - */ 67 + ostm_timer_stop(to); 69 68 70 - ostm_timer_stop(ostm); 69 + writel(0, timer_of_base(to) + OSTM_CMP); 70 + writeb(CTL_FREERUN, timer_of_base(to) + OSTM_CTL); 71 + writeb(TS, timer_of_base(to) + OSTM_TS); 71 72 72 - writel(0, ostm->base + OSTM_CMP); 73 - writeb(CTL_FREERUN, ostm->base + OSTM_CTL); 74 - writeb(TS, ostm->base + OSTM_TS); 75 - 76 - return clocksource_mmio_init(ostm->base + OSTM_CNT, 77 - "ostm", rate, 78 - 300, 32, clocksource_mmio_readl_up); 73 + return clocksource_mmio_init(timer_of_base(to) + OSTM_CNT, 74 + to->np->full_name, timer_of_rate(to), 300, 75 + 32, clocksource_mmio_readl_up); 79 76 } 80 77 81 78 static u64 notrace ostm_read_sched_clock(void) ··· 74 89 return readl(system_clock); 75 90 } 76 91 77 - static void __init ostm_init_sched_clock(struct ostm_device *ostm, 78 - unsigned long rate) 92 + static void __init ostm_init_sched_clock(struct timer_of *to) 79 93 { 80 - system_clock = ostm->base + OSTM_CNT; 81 - sched_clock_register(ostm_read_sched_clock, 32, rate); 94 + system_clock = timer_of_base(to) + OSTM_CNT; 95 + sched_clock_register(ostm_read_sched_clock, 32, timer_of_rate(to)); 82 96 } 83 97 84 98 static int ostm_clock_event_next(unsigned long delta, 85 - struct clock_event_device *ced) 99 + struct clock_event_device *ced) 86 100 { 87 - struct ostm_device *ostm = ced_to_ostm(ced); 101 + struct timer_of *to = to_timer_of(ced); 88 102 89 - ostm_timer_stop(ostm); 103 + ostm_timer_stop(to); 90 104 91 - writel(delta, ostm->base + OSTM_CMP); 92 - writeb(CTL_ONESHOT, ostm->base + OSTM_CTL); 93 - writeb(TS, ostm->base + OSTM_TS); 105 + writel(delta, timer_of_base(to) + OSTM_CMP); 106 + writeb(CTL_ONESHOT, timer_of_base(to) + OSTM_CTL); 107 + writeb(TS, timer_of_base(to) + OSTM_TS); 94 108 95 109 return 0; 96 110 } 97 111 98 112 static int ostm_shutdown(struct clock_event_device *ced) 99 113 { 100 - struct ostm_device *ostm = ced_to_ostm(ced); 114 + struct timer_of *to = to_timer_of(ced); 101 115 102 - ostm_timer_stop(ostm); 116 + ostm_timer_stop(to); 103 117 104 118 return 0; 105 119 } 106 120 static int ostm_set_periodic(struct clock_event_device *ced) 107 121 { 108 - struct ostm_device *ostm = ced_to_ostm(ced); 122 + struct timer_of *to = to_timer_of(ced); 109 123 110 124 if (clockevent_state_oneshot(ced) || clockevent_state_periodic(ced)) 111 - ostm_timer_stop(ostm); 125 + ostm_timer_stop(to); 112 126 113 - writel(ostm->ticks_per_jiffy - 1, ostm->base + OSTM_CMP); 114 - writeb(CTL_PERIODIC, ostm->base + OSTM_CTL); 115 - writeb(TS, ostm->base + OSTM_TS); 127 + writel(timer_of_period(to) - 1, timer_of_base(to) + OSTM_CMP); 128 + writeb(CTL_PERIODIC, timer_of_base(to) + OSTM_CTL); 129 + writeb(TS, timer_of_base(to) + OSTM_TS); 116 130 117 131 return 0; 118 132 } 119 133 120 134 static int ostm_set_oneshot(struct clock_event_device *ced) 121 135 { 122 - struct ostm_device *ostm = ced_to_ostm(ced); 136 + struct timer_of *to = to_timer_of(ced); 123 137 124 - ostm_timer_stop(ostm); 138 + ostm_timer_stop(to); 125 139 126 140 return 0; 127 141 } 128 142 129 143 static irqreturn_t ostm_timer_interrupt(int irq, void *dev_id) 130 144 { 131 - struct ostm_device *ostm = dev_id; 145 + struct clock_event_device *ced = dev_id; 132 146 133 - if (clockevent_state_oneshot(&ostm->ced)) 134 - ostm_timer_stop(ostm); 147 + if (clockevent_state_oneshot(ced)) 148 + ostm_timer_stop(to_timer_of(ced)); 135 149 136 150 /* notify clockevent layer */ 137 - if (ostm->ced.event_handler) 138 - ostm->ced.event_handler(&ostm->ced); 151 + if (ced->event_handler) 152 + ced->event_handler(ced); 139 153 140 154 return IRQ_HANDLED; 141 155 } 142 156 143 - static int __init ostm_init_clkevt(struct ostm_device *ostm, int irq, 144 - unsigned long rate) 157 + static int __init ostm_init_clkevt(struct timer_of *to) 145 158 { 146 - struct clock_event_device *ced = &ostm->ced; 147 - int ret = -ENXIO; 159 + struct clock_event_device *ced = &to->clkevt; 148 160 149 - ret = request_irq(irq, ostm_timer_interrupt, 150 - IRQF_TIMER | IRQF_IRQPOLL, 151 - "ostm", ostm); 152 - if (ret) { 153 - pr_err("ostm: failed to request irq\n"); 154 - return ret; 155 - } 156 - 157 - ced->name = "ostm"; 158 161 ced->features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC; 159 162 ced->set_state_shutdown = ostm_shutdown; 160 163 ced->set_state_periodic = ostm_set_periodic; ··· 151 178 ced->shift = 32; 152 179 ced->rating = 300; 153 180 ced->cpumask = cpumask_of(0); 154 - clockevents_config_and_register(ced, rate, 0xf, 0xffffffff); 181 + clockevents_config_and_register(ced, timer_of_rate(to), 0xf, 182 + 0xffffffff); 155 183 156 184 return 0; 157 185 } 158 186 159 187 static int __init ostm_init(struct device_node *np) 160 188 { 161 - struct ostm_device *ostm; 162 - int ret = -EFAULT; 163 - struct clk *ostm_clk = NULL; 164 - int irq; 165 - unsigned long rate; 189 + struct timer_of *to; 190 + int ret; 166 191 167 - ostm = kzalloc(sizeof(*ostm), GFP_KERNEL); 168 - if (!ostm) 192 + to = kzalloc(sizeof(*to), GFP_KERNEL); 193 + if (!to) 169 194 return -ENOMEM; 170 195 171 - ostm->base = of_iomap(np, 0); 172 - if (!ostm->base) { 173 - pr_err("ostm: failed to remap I/O memory\n"); 174 - goto err; 196 + to->flags = TIMER_OF_BASE | TIMER_OF_CLOCK; 197 + if (system_clock) { 198 + /* 199 + * clock sources don't use interrupts, clock events do 200 + */ 201 + to->flags |= TIMER_OF_IRQ; 202 + to->of_irq.flags = IRQF_TIMER | IRQF_IRQPOLL; 203 + to->of_irq.handler = ostm_timer_interrupt; 175 204 } 176 205 177 - irq = irq_of_parse_and_map(np, 0); 178 - if (irq < 0) { 179 - pr_err("ostm: Failed to get irq\n"); 180 - goto err; 181 - } 182 - 183 - ostm_clk = of_clk_get(np, 0); 184 - if (IS_ERR(ostm_clk)) { 185 - pr_err("ostm: Failed to get clock\n"); 186 - ostm_clk = NULL; 187 - goto err; 188 - } 189 - 190 - ret = clk_prepare_enable(ostm_clk); 191 - if (ret) { 192 - pr_err("ostm: Failed to enable clock\n"); 193 - goto err; 194 - } 195 - 196 - rate = clk_get_rate(ostm_clk); 197 - ostm->ticks_per_jiffy = DIV_ROUND_CLOSEST(rate, HZ); 206 + ret = timer_of_init(np, to); 207 + if (ret) 208 + goto err_free; 198 209 199 210 /* 200 211 * First probed device will be used as system clocksource. Any 201 212 * additional devices will be used as clock events. 202 213 */ 203 214 if (!system_clock) { 204 - ret = ostm_init_clksrc(ostm, rate); 215 + ret = ostm_init_clksrc(to); 216 + if (ret) 217 + goto err_cleanup; 205 218 206 - if (!ret) { 207 - ostm_init_sched_clock(ostm, rate); 208 - pr_info("ostm: used for clocksource\n"); 209 - } 210 - 219 + ostm_init_sched_clock(to); 220 + pr_info("%pOF: used for clocksource\n", np); 211 221 } else { 212 - ret = ostm_init_clkevt(ostm, irq, rate); 222 + ret = ostm_init_clkevt(to); 223 + if (ret) 224 + goto err_cleanup; 213 225 214 - if (!ret) 215 - pr_info("ostm: used for clock events\n"); 216 - } 217 - 218 - err: 219 - if (ret) { 220 - clk_disable_unprepare(ostm_clk); 221 - iounmap(ostm->base); 222 - kfree(ostm); 223 - return ret; 226 + pr_info("%pOF: used for clock events\n", np); 224 227 } 225 228 226 229 return 0; 230 + 231 + err_cleanup: 232 + timer_of_cleanup(to); 233 + err_free: 234 + kfree(to); 235 + return ret; 227 236 } 228 237 229 238 TIMER_OF_DECLARE(ostm, "renesas,ostm", ostm_init);
+3 -3
drivers/clocksource/timer-of.c
··· 57 57 if (of_irq->name) { 58 58 of_irq->irq = ret = of_irq_get_byname(np, of_irq->name); 59 59 if (ret < 0) { 60 - pr_err("Failed to get interrupt %s for %s\n", 61 - of_irq->name, np->full_name); 60 + pr_err("Failed to get interrupt %s for %pOF\n", 61 + of_irq->name, np); 62 62 return ret; 63 63 } 64 64 } else { ··· 192 192 } 193 193 194 194 if (!to->clkevt.name) 195 - to->clkevt.name = np->name; 195 + to->clkevt.name = np->full_name; 196 196 197 197 to->np = np; 198 198