summaryrefslogtreecommitdiffstats
path: root/src/southbridge/intel/common/hpet.c
blob: e9369ee54025ef335dbf6ba1936036f558c1893d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* SPDX-License-Identifier: GPL-2.0-only */

#include <arch/hpet.h>
#include <southbridge/intel/common/rcba.h>
#include <stdint.h>

#include "hpet.h"

#define HPTC		0x3404

#define HPET32(x) (*((volatile u32 *)(HPET_BASE_ADDRESS + (x))))

void enable_hpet(void)
{
	u32 reg32;
	reg32 = RCBA32(HPTC);
	reg32 &= ~0x03;
	reg32 |= (1 << 7);
	RCBA32(HPTC) = reg32;
	/* Read back for posted write to take effect */
	RCBA32(HPTC);
	HPET32(0x10) = HPET32(0x10) | 1;
}

void hpet_udelay(u32 delay)
{
	u32 start, finish, now;

	delay *= 15; /* now in usec */

	start = HPET32(0xf0);
	finish = start + delay;
	while (1) {
		now = HPET32(0xf0);
		if (finish > start) {
			if (now >= finish)
				break;
		} else {
			if ((now < start) && (now >= finish))
				break;
		}
	}
}