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

clocksource/drivers/timer-milbeaut: Cleanup common register accesses

Aggregate common register accesses into shared functions for
maintainability.

Signed-off-by: Sugaya Taichi <sugaya.taichi@socionext.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

authored by

Sugaya Taichi and committed by
Daniel Lezcano
37dbf65c 95d5dc71

+41 -25
+41 -25
drivers/clocksource/timer-milbeaut.c
··· 26 26 #define MLB_TMR_TMCSR_CSL_DIV2 0 27 27 #define MLB_TMR_DIV_CNT 2 28 28 29 - #define MLB_TMR_SRC_CH (1) 30 - #define MLB_TMR_EVT_CH (0) 29 + #define MLB_TMR_SRC_CH 1 30 + #define MLB_TMR_EVT_CH 0 31 31 32 32 #define MLB_TMR_SRC_CH_OFS (MLB_TMR_REGSZPCH * MLB_TMR_SRC_CH) 33 33 #define MLB_TMR_EVT_CH_OFS (MLB_TMR_REGSZPCH * MLB_TMR_EVT_CH) ··· 43 43 #define MLB_TMR_EVT_TMRLR2_OFS (MLB_TMR_EVT_CH_OFS + MLB_TMR_TMRLR2_OFS) 44 44 45 45 #define MLB_TIMER_RATING 500 46 + #define MLB_TIMER_ONESHOT 0 47 + #define MLB_TIMER_PERIODIC 1 46 48 47 49 static irqreturn_t mlb_timer_interrupt(int irq, void *dev_id) 48 50 { ··· 61 59 return IRQ_HANDLED; 62 60 } 63 61 62 + static void mlb_evt_timer_start(struct timer_of *to, bool periodic) 63 + { 64 + u32 val = MLB_TMR_TMCSR_CSL_DIV2; 65 + 66 + val |= MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_TRG | MLB_TMR_TMCSR_INTE; 67 + if (periodic) 68 + val |= MLB_TMR_TMCSR_RELD; 69 + writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); 70 + } 71 + 72 + static void mlb_evt_timer_stop(struct timer_of *to) 73 + { 74 + u32 val = readl_relaxed(timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); 75 + 76 + val &= ~MLB_TMR_TMCSR_CNTE; 77 + writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); 78 + } 79 + 80 + static void mlb_evt_timer_register_count(struct timer_of *to, unsigned long cnt) 81 + { 82 + writel_relaxed(cnt, timer_of_base(to) + MLB_TMR_EVT_TMRLR1_OFS); 83 + } 84 + 64 85 static int mlb_set_state_periodic(struct clock_event_device *clk) 65 86 { 66 87 struct timer_of *to = to_timer_of(clk); 67 - u32 val = MLB_TMR_TMCSR_CSL_DIV2; 68 88 69 - writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); 70 - 71 - writel_relaxed(to->of_clk.period, timer_of_base(to) + 72 - MLB_TMR_EVT_TMRLR1_OFS); 73 - val |= MLB_TMR_TMCSR_RELD | MLB_TMR_TMCSR_CNTE | 74 - MLB_TMR_TMCSR_TRG | MLB_TMR_TMCSR_INTE; 75 - writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); 89 + mlb_evt_timer_stop(to); 90 + mlb_evt_timer_register_count(to, to->of_clk.period); 91 + mlb_evt_timer_start(to, MLB_TIMER_PERIODIC); 76 92 return 0; 77 93 } 78 94 79 95 static int mlb_set_state_oneshot(struct clock_event_device *clk) 80 96 { 81 97 struct timer_of *to = to_timer_of(clk); 82 - u32 val = MLB_TMR_TMCSR_CSL_DIV2; 83 98 84 - writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); 85 - val |= MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_TRG | MLB_TMR_TMCSR_INTE; 86 - writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); 99 + mlb_evt_timer_stop(to); 100 + mlb_evt_timer_start(to, MLB_TIMER_ONESHOT); 87 101 return 0; 88 102 } 89 103 90 104 static int mlb_set_state_shutdown(struct clock_event_device *clk) 91 105 { 92 106 struct timer_of *to = to_timer_of(clk); 93 - u32 val = MLB_TMR_TMCSR_CSL_DIV2; 94 107 95 - writel_relaxed(val, timer_of_base(to) + MLB_TMR_EVT_TMCSR_OFS); 108 + mlb_evt_timer_stop(to); 96 109 return 0; 97 110 } 98 111 ··· 116 99 { 117 100 struct timer_of *to = to_timer_of(clk); 118 101 119 - writel_relaxed(event, timer_of_base(to) + MLB_TMR_EVT_TMRLR1_OFS); 120 - writel_relaxed(MLB_TMR_TMCSR_CSL_DIV2 | 121 - MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_INTE | 122 - MLB_TMR_TMCSR_TRG, timer_of_base(to) + 123 - MLB_TMR_EVT_TMCSR_OFS); 102 + mlb_evt_timer_stop(to); 103 + mlb_evt_timer_register_count(to, event); 104 + mlb_evt_timer_start(to, MLB_TIMER_ONESHOT); 124 105 return 0; 125 106 } 126 107 127 108 static int mlb_config_clock_source(struct timer_of *to) 128 109 { 129 - writel_relaxed(0, timer_of_base(to) + MLB_TMR_SRC_TMCSR_OFS); 130 - writel_relaxed(~0, timer_of_base(to) + MLB_TMR_SRC_TMR_OFS); 110 + u32 val = MLB_TMR_TMCSR_CSL_DIV2; 111 + 112 + writel_relaxed(val, timer_of_base(to) + MLB_TMR_SRC_TMCSR_OFS); 131 113 writel_relaxed(~0, timer_of_base(to) + MLB_TMR_SRC_TMRLR1_OFS); 132 114 writel_relaxed(~0, timer_of_base(to) + MLB_TMR_SRC_TMRLR2_OFS); 133 - writel_relaxed(BIT(4) | BIT(1) | BIT(0), timer_of_base(to) + 134 - MLB_TMR_SRC_TMCSR_OFS); 115 + val |= MLB_TMR_TMCSR_RELD | MLB_TMR_TMCSR_CNTE | MLB_TMR_TMCSR_TRG; 116 + writel_relaxed(val, timer_of_base(to) + MLB_TMR_SRC_TMCSR_OFS); 135 117 return 0; 136 118 } 137 119