3 #include "nouveau_drv.h"
4 #include "nouveau_drm.h"
5 #include "nouveau_hw.h"
8 nv04_timer_init(struct drm_device
*dev
)
10 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
13 nv_wr32(dev
, NV04_PTIMER_INTR_EN_0
, 0x00000000);
14 nv_wr32(dev
, NV04_PTIMER_INTR_0
, 0xFFFFFFFF);
16 /* aim for 31.25MHz, which gives us nanosecond timestamps */
19 /* determine base clock for timer source */
20 if (dev_priv
->chipset
< 0x40) {
21 n
= nouveau_hw_get_clock(dev
, PLL_CORE
);
23 if (dev_priv
->chipset
== 0x40) {
24 /*XXX: figure this out */
27 n
= dev_priv
->crystal
;
34 nv_wr32(dev
, 0x009220, m
- 1);
38 NV_WARN(dev
, "PTIMER: unknown input clock freq\n");
39 if (!nv_rd32(dev
, NV04_PTIMER_NUMERATOR
) ||
40 !nv_rd32(dev
, NV04_PTIMER_DENOMINATOR
)) {
41 nv_wr32(dev
, NV04_PTIMER_NUMERATOR
, 1);
42 nv_wr32(dev
, NV04_PTIMER_DENOMINATOR
, 1);
47 /* reduce ratio to acceptable values */
48 while (((n
% 5) == 0) && ((d
% 5) == 0)) {
53 while (((n
% 2) == 0) && ((d
% 2) == 0)) {
58 while (n
> 0xffff || d
> 0xffff) {
63 nv_wr32(dev
, NV04_PTIMER_NUMERATOR
, n
);
64 nv_wr32(dev
, NV04_PTIMER_DENOMINATOR
, d
);
69 nv04_timer_read(struct drm_device
*dev
)
74 hi
= nv_rd32(dev
, NV04_PTIMER_TIME_1
);
75 lo
= nv_rd32(dev
, NV04_PTIMER_TIME_0
);
76 } while (hi
!= nv_rd32(dev
, NV04_PTIMER_TIME_1
));
78 return ((u64
)hi
<< 32 | lo
);
82 nv04_timer_takedown(struct drm_device
*dev
)