1 /*
2 * Copyright 2017 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
23 */
24 #include "head.h"
25
26 static void
nv04_head_vblank_put(struct nvkm_head * head)27 nv04_head_vblank_put(struct nvkm_head *head)
28 {
29 struct nvkm_device *device = head->disp->engine.subdev.device;
30 nvkm_wr32(device, 0x600140 + (head->id * 0x2000) , 0x00000000);
31 }
32
33 static void
nv04_head_vblank_get(struct nvkm_head * head)34 nv04_head_vblank_get(struct nvkm_head *head)
35 {
36 struct nvkm_device *device = head->disp->engine.subdev.device;
37 nvkm_wr32(device, 0x600140 + (head->id * 0x2000) , 0x00000001);
38 }
39
40 static void
nv04_head_rgpos(struct nvkm_head * head,u16 * hline,u16 * vline)41 nv04_head_rgpos(struct nvkm_head *head, u16 *hline, u16 *vline)
42 {
43 struct nvkm_device *device = head->disp->engine.subdev.device;
44 u32 data = nvkm_rd32(device, 0x600868 + (head->id * 0x2000));
45 *hline = (data & 0xffff0000) >> 16;
46 *vline = (data & 0x0000ffff);
47 }
48
49 static void
nv04_head_state(struct nvkm_head * head,struct nvkm_head_state * state)50 nv04_head_state(struct nvkm_head *head, struct nvkm_head_state *state)
51 {
52 struct nvkm_device *device = head->disp->engine.subdev.device;
53 const u32 hoff = head->id * 0x0200;
54 state->vblanks = nvkm_rd32(device, 0x680800 + hoff) & 0x0000ffff;
55 state->vtotal = nvkm_rd32(device, 0x680804 + hoff) & 0x0000ffff;
56 state->vblanke = state->vtotal - 1;
57 state->hblanks = nvkm_rd32(device, 0x680820 + hoff) & 0x0000ffff;
58 state->htotal = nvkm_rd32(device, 0x680824 + hoff) & 0x0000ffff;
59 state->hblanke = state->htotal - 1;
60 }
61
62 static const struct nvkm_head_func
63 nv04_head = {
64 .state = nv04_head_state,
65 .rgpos = nv04_head_rgpos,
66 .vblank_get = nv04_head_vblank_get,
67 .vblank_put = nv04_head_vblank_put,
68 };
69
70 int
nv04_head_new(struct nvkm_disp * disp,int id)71 nv04_head_new(struct nvkm_disp *disp, int id)
72 {
73 return nvkm_head_new_(&nv04_head, disp, id);
74 }
75