1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "priv.h"
25#include "regsnv04.h"
26
27static void
28nv41_timer_init(struct nvkm_timer *tmr)
29{
30 struct nvkm_subdev *subdev = &tmr->subdev;
31 struct nvkm_device *device = subdev->device;
32 u32 f = device->crystal;
33 u32 m = 1, n, d;
34
35
36 d = 1000000 / 32;
37 n = f;
38
39 while (n < (d * 2)) {
40 n += (n / m);
41 m++;
42 }
43
44
45 while (((n % 5) == 0) && ((d % 5) == 0)) {
46 n /= 5;
47 d /= 5;
48 }
49
50 while (((n % 2) == 0) && ((d % 2) == 0)) {
51 n /= 2;
52 d /= 2;
53 }
54
55 while (n > 0xffff || d > 0xffff) {
56 n >>= 1;
57 d >>= 1;
58 }
59
60 nvkm_debug(subdev, "input frequency : %dHz\n", f);
61 nvkm_debug(subdev, "input multiplier: %d\n", m);
62 nvkm_debug(subdev, "numerator : %08x\n", n);
63 nvkm_debug(subdev, "denominator : %08x\n", d);
64 nvkm_debug(subdev, "timer frequency : %dHz\n", (f * m) * d / n);
65
66 nvkm_wr32(device, 0x009220, m - 1);
67 nvkm_wr32(device, NV04_PTIMER_NUMERATOR, n);
68 nvkm_wr32(device, NV04_PTIMER_DENOMINATOR, d);
69}
70
71static const struct nvkm_timer_func
72nv41_timer = {
73 .init = nv41_timer_init,
74 .intr = nv04_timer_intr,
75 .read = nv04_timer_read,
76 .time = nv04_timer_time,
77 .alarm_init = nv04_timer_alarm_init,
78 .alarm_fini = nv04_timer_alarm_fini,
79};
80
81int
82nv41_timer_new(struct nvkm_device *device, int index, struct nvkm_timer **ptmr)
83{
84 return nvkm_timer_new_(&nv41_timer, device, index, ptmr);
85}
86