Commit e3280b2a authored by Viresh Kumar's avatar Viresh Kumar Committed by Ralf Baechle

MIPS: loongson64/timer: Migrate to new 'set-state' interface

Migrate loongson 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.

[ralf@linux-mips.org: Folded in Viresh's followon fix.]
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Cc: Huacai Chen <chenhc@lemote.com>
Cc: Michael Opdenacker <michael.opdenacker@free-electrons.com>
Cc: Hongliang Tao <taohl@lemote.com>
Cc: Valentin Rothberg <valentinrothberg@gmail.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: linux-mips@linux-mips.org
Cc: linaro-kernel@lists.linaro.org
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Patchwork: https://patchwork.linux-mips.org/patch/10608/
Patchwork: https://patchwork.linux-mips.org/patch/10883/Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent d199da55
...@@ -51,40 +51,36 @@ void enable_mfgpt0_counter(void) ...@@ -51,40 +51,36 @@ void enable_mfgpt0_counter(void)
} }
EXPORT_SYMBOL(enable_mfgpt0_counter); EXPORT_SYMBOL(enable_mfgpt0_counter);
static void init_mfgpt_timer(enum clock_event_mode mode, static int mfgpt_timer_set_periodic(struct clock_event_device *evt)
struct clock_event_device *evt)
{ {
raw_spin_lock(&mfgpt_lock); raw_spin_lock(&mfgpt_lock);
switch (mode) { outw(COMPARE, MFGPT0_CMP2); /* set comparator2 */
case CLOCK_EVT_MODE_PERIODIC: outw(0, MFGPT0_CNT); /* set counter to 0 */
outw(COMPARE, MFGPT0_CMP2); /* set comparator2 */ enable_mfgpt0_counter();
outw(0, MFGPT0_CNT); /* set counter to 0 */
enable_mfgpt0_counter();
break;
case CLOCK_EVT_MODE_SHUTDOWN:
case CLOCK_EVT_MODE_UNUSED:
if (evt->mode == CLOCK_EVT_MODE_PERIODIC ||
evt->mode == CLOCK_EVT_MODE_ONESHOT)
disable_mfgpt0_counter();
break;
case CLOCK_EVT_MODE_ONESHOT:
/* The oneshot mode have very high deviation, Not use it! */
break;
case CLOCK_EVT_MODE_RESUME:
/* Nothing to do here */
break;
}
raw_spin_unlock(&mfgpt_lock); raw_spin_unlock(&mfgpt_lock);
return 0;
}
static int mfgpt_timer_shutdown(struct clock_event_device *evt)
{
if (clockevent_state_periodic(evt) || clockevent_state_oneshot(evt)) {
raw_spin_lock(&mfgpt_lock);
disable_mfgpt0_counter();
raw_spin_unlock(&mfgpt_lock);
}
return 0;
} }
static struct clock_event_device mfgpt_clockevent = { static struct clock_event_device mfgpt_clockevent = {
.name = "mfgpt", .name = "mfgpt",
.features = CLOCK_EVT_FEAT_PERIODIC, .features = CLOCK_EVT_FEAT_PERIODIC,
.set_mode = init_mfgpt_timer,
/* The oneshot mode have very high deviation, don't use it! */
.set_state_shutdown = mfgpt_timer_shutdown,
.set_state_periodic = mfgpt_timer_set_periodic,
.irq = CS5536_MFGPT_INTR, .irq = CS5536_MFGPT_INTR,
}; };
......
...@@ -78,55 +78,77 @@ static void hpet_enable_legacy_int(void) ...@@ -78,55 +78,77 @@ static void hpet_enable_legacy_int(void)
/* Do nothing on Loongson-3 */ /* Do nothing on Loongson-3 */
} }
static void hpet_set_mode(enum clock_event_mode mode, static int hpet_set_state_periodic(struct clock_event_device *evt)
struct clock_event_device *evt)
{ {
int cfg = 0; int cfg;
spin_lock(&hpet_lock); spin_lock(&hpet_lock);
switch (mode) {
case CLOCK_EVT_MODE_PERIODIC: pr_info("set clock event to periodic mode!\n");
pr_info("set clock event to periodic mode!\n"); /* stop counter */
/* stop counter */ hpet_stop_counter();
hpet_stop_counter();
/* enables the timer0 to generate a periodic interrupt */
/* enables the timer0 to generate a periodic interrupt */ cfg = hpet_read(HPET_T0_CFG);
cfg = hpet_read(HPET_T0_CFG); cfg &= ~HPET_TN_LEVEL;
cfg &= ~HPET_TN_LEVEL; cfg |= HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_SETVAL |
cfg |= HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_32BIT;
HPET_TN_SETVAL | HPET_TN_32BIT; hpet_write(HPET_T0_CFG, cfg);
hpet_write(HPET_T0_CFG, cfg);
/* set the comparator */
/* set the comparator */ hpet_write(HPET_T0_CMP, HPET_COMPARE_VAL);
hpet_write(HPET_T0_CMP, HPET_COMPARE_VAL); udelay(1);
udelay(1); hpet_write(HPET_T0_CMP, HPET_COMPARE_VAL);
hpet_write(HPET_T0_CMP, HPET_COMPARE_VAL);
/* start counter */
/* start counter */ hpet_start_counter();
hpet_start_counter();
break; spin_unlock(&hpet_lock);
case CLOCK_EVT_MODE_SHUTDOWN: return 0;
case CLOCK_EVT_MODE_UNUSED: }
cfg = hpet_read(HPET_T0_CFG);
cfg &= ~HPET_TN_ENABLE; static int hpet_set_state_shutdown(struct clock_event_device *evt)
hpet_write(HPET_T0_CFG, cfg); {
break; int cfg;
case CLOCK_EVT_MODE_ONESHOT:
pr_info("set clock event to one shot mode!\n"); spin_lock(&hpet_lock);
cfg = hpet_read(HPET_T0_CFG);
/* set timer0 type cfg = hpet_read(HPET_T0_CFG);
* 1 : periodic interrupt cfg &= ~HPET_TN_ENABLE;
* 0 : non-periodic(oneshot) interrupt hpet_write(HPET_T0_CFG, cfg);
*/
cfg &= ~HPET_TN_PERIODIC;
cfg |= HPET_TN_ENABLE | HPET_TN_32BIT;
hpet_write(HPET_T0_CFG, cfg);
break;
case CLOCK_EVT_MODE_RESUME:
hpet_enable_legacy_int();
break;
}
spin_unlock(&hpet_lock); spin_unlock(&hpet_lock);
return 0;
}
static int hpet_set_state_oneshot(struct clock_event_device *evt)
{
int cfg;
spin_lock(&hpet_lock);
pr_info("set clock event to one shot mode!\n");
cfg = hpet_read(HPET_T0_CFG);
/*
* set timer0 type
* 1 : periodic interrupt
* 0 : non-periodic(oneshot) interrupt
*/
cfg &= ~HPET_TN_PERIODIC;
cfg |= HPET_TN_ENABLE | HPET_TN_32BIT;
hpet_write(HPET_T0_CFG, cfg);
spin_unlock(&hpet_lock);
return 0;
}
static int hpet_tick_resume(struct clock_event_device *evt)
{
spin_lock(&hpet_lock);
hpet_enable_legacy_int();
spin_unlock(&hpet_lock);
return 0;
} }
static int hpet_next_event(unsigned long delta, static int hpet_next_event(unsigned long delta,
...@@ -206,7 +228,10 @@ void __init setup_hpet_timer(void) ...@@ -206,7 +228,10 @@ void __init setup_hpet_timer(void)
cd->name = "hpet"; cd->name = "hpet";
cd->rating = 320; cd->rating = 320;
cd->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; cd->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
cd->set_mode = hpet_set_mode; cd->set_state_shutdown = hpet_set_state_shutdown;
cd->set_state_periodic = hpet_set_state_periodic;
cd->set_state_oneshot = hpet_set_state_oneshot;
cd->tick_resume = hpet_tick_resume;
cd->set_next_event = hpet_next_event; cd->set_next_event = hpet_next_event;
cd->irq = HPET_T0_IRQ; cd->irq = HPET_T0_IRQ;
cd->cpumask = cpumask_of(cpu); cd->cpumask = cpumask_of(cpu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment