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

clockevents/drivers/i8253: Migrate to new 'set-state' interface

Migrate i8253 driver to the new 'set-state' interface provided by
clockevents core, the earlier 'set-mode' interface is marked obsolete
now.

This also enables us to implement callbacks for new states of clockevent
devices, for example: ONESHOT_STOPPED.

Cc: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

authored by

Viresh Kumar and committed by
Daniel Lezcano
8eda41b0 73766340

+38 -39
+1 -1
arch/x86/kernel/i8253.c
··· 34 34 * - when local APIC timer is active (PIT is switched off) 35 35 */ 36 36 if (num_possible_cpus() > 1 || is_hpet_enabled() || 37 - i8253_clockevent.mode != CLOCK_EVT_MODE_PERIODIC) 37 + !clockevent_state_periodic(&i8253_clockevent)) 38 38 return 0; 39 39 40 40 return clocksource_i8253_init();
+37 -38
drivers/clocksource/i8253.c
··· 100 100 #endif 101 101 102 102 #ifdef CONFIG_CLKEVT_I8253 103 - /* 104 - * Initialize the PIT timer. 105 - * 106 - * This is also called after resume to bring the PIT into operation again. 107 - */ 108 - static void init_pit_timer(enum clock_event_mode mode, 109 - struct clock_event_device *evt) 103 + static int pit_shutdown(struct clock_event_device *evt) 104 + { 105 + if (!clockevent_state_oneshot(evt) && !clockevent_state_periodic(evt)) 106 + return 0; 107 + 108 + raw_spin_lock(&i8253_lock); 109 + 110 + outb_p(0x30, PIT_MODE); 111 + outb_p(0, PIT_CH0); 112 + outb_p(0, PIT_CH0); 113 + 114 + raw_spin_unlock(&i8253_lock); 115 + return 0; 116 + } 117 + 118 + static int pit_set_oneshot(struct clock_event_device *evt) 119 + { 120 + raw_spin_lock(&i8253_lock); 121 + outb_p(0x38, PIT_MODE); 122 + raw_spin_unlock(&i8253_lock); 123 + return 0; 124 + } 125 + 126 + static int pit_set_periodic(struct clock_event_device *evt) 110 127 { 111 128 raw_spin_lock(&i8253_lock); 112 129 113 - switch (mode) { 114 - case CLOCK_EVT_MODE_PERIODIC: 115 - /* binary, mode 2, LSB/MSB, ch 0 */ 116 - outb_p(0x34, PIT_MODE); 117 - outb_p(PIT_LATCH & 0xff , PIT_CH0); /* LSB */ 118 - outb_p(PIT_LATCH >> 8 , PIT_CH0); /* MSB */ 119 - break; 130 + /* binary, mode 2, LSB/MSB, ch 0 */ 131 + outb_p(0x34, PIT_MODE); 132 + outb_p(PIT_LATCH & 0xff, PIT_CH0); /* LSB */ 133 + outb_p(PIT_LATCH >> 8, PIT_CH0); /* MSB */ 120 134 121 - case CLOCK_EVT_MODE_SHUTDOWN: 122 - case CLOCK_EVT_MODE_UNUSED: 123 - if (evt->mode == CLOCK_EVT_MODE_PERIODIC || 124 - evt->mode == CLOCK_EVT_MODE_ONESHOT) { 125 - outb_p(0x30, PIT_MODE); 126 - outb_p(0, PIT_CH0); 127 - outb_p(0, PIT_CH0); 128 - } 129 - break; 130 - 131 - case CLOCK_EVT_MODE_ONESHOT: 132 - /* One shot setup */ 133 - outb_p(0x38, PIT_MODE); 134 - break; 135 - 136 - case CLOCK_EVT_MODE_RESUME: 137 - /* Nothing to do here */ 138 - break; 139 - } 140 135 raw_spin_unlock(&i8253_lock); 136 + return 0; 141 137 } 142 138 143 139 /* ··· 156 160 * it can be solely used for the global tick. 157 161 */ 158 162 struct clock_event_device i8253_clockevent = { 159 - .name = "pit", 160 - .features = CLOCK_EVT_FEAT_PERIODIC, 161 - .set_mode = init_pit_timer, 162 - .set_next_event = pit_next_event, 163 + .name = "pit", 164 + .features = CLOCK_EVT_FEAT_PERIODIC, 165 + .set_state_shutdown = pit_shutdown, 166 + .set_state_periodic = pit_set_periodic, 167 + .set_next_event = pit_next_event, 163 168 }; 164 169 165 170 /* ··· 169 172 */ 170 173 void __init clockevent_i8253_init(bool oneshot) 171 174 { 172 - if (oneshot) 175 + if (oneshot) { 173 176 i8253_clockevent.features |= CLOCK_EVT_FEAT_ONESHOT; 177 + i8253_clockevent.set_state_oneshot = pit_set_oneshot; 178 + } 174 179 /* 175 180 * Start pit with the boot cpu mask. x86 might make it global 176 181 * when it is used as broadcast device later.