Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f37632d1 authored by Yoshinori Sato's avatar Yoshinori Sato Committed by Daniel Lezcano
Browse files

clocksource/drivers/h8300: Simplify delta handling

parent 2f445e0a
Loading
Loading
Loading
Loading
+6 −34
Original line number Diff line number Diff line
@@ -36,57 +36,29 @@ struct timer8_priv {
	unsigned int tcora;
};

static unsigned long timer8_get_counter(struct timer8_priv *p)
{
	unsigned long v1, v2, v3;
	int o1, o2;

	o1 = readb(p->mapbase + _8TCSR) & 0x20;

	/* Make sure the timer value is stable. Stolen from acpi_pm.c */
	do {
		o2 = o1;
		v1 = readw(p->mapbase + _8TCNT);
		v2 = readw(p->mapbase + _8TCNT);
		v3 = readw(p->mapbase + _8TCNT);
		o1 = readb(p->mapbase + _8TCSR) & 0x20;
	} while (unlikely((o1 != o2) || (v1 > v2 && v1 < v3)
			  || (v2 > v3 && v2 < v1) || (v3 > v1 && v3 < v2)));

	v2 |= o1 << 10;
	return v2;
}

static irqreturn_t timer8_interrupt(int irq, void *dev_id)
{
	struct timer8_priv *p = dev_id;

	writeb(readb(p->mapbase + _8TCSR) & ~0x40,
		  p->mapbase + _8TCSR);

	writew(p->tcora, p->mapbase + TCORA);

	if (clockevent_state_oneshot(&p->ced))
		writew(0x0000, p->mapbase + _8TCR);

	p->ced.event_handler(&p->ced);

	writeb(readb(p->mapbase + _8TCSR) & ~0x40,
		  p->mapbase + _8TCSR);

	return IRQ_HANDLED;
}

static void timer8_set_next(struct timer8_priv *p, unsigned long delta)
{
	unsigned long now;

	if (delta >= 0x10000)
		pr_warn("delta out of range\n");
	now = timer8_get_counter(p);
	p->tcora = delta;
	writeb(readb(p->mapbase + _8TCR) | 0x40, p->mapbase + _8TCR);
	if (delta > now)
	writeb(readb(p->mapbase + _8TCR) & ~0x40, p->mapbase + _8TCR);
	writew(0, p->mapbase + _8TCNT);
	writew(delta, p->mapbase + TCORA);
	else
		writew(now + 1, p->mapbase + TCORA);
	writeb(readb(p->mapbase + _8TCR) | 0x40, p->mapbase + _8TCR);
}

static int timer8_enable(struct timer8_priv *p)