xref: /linux/drivers/gpu/drm/nouveau/nvkm/engine/disp/nv04.c (revision 2da68a77)
1 /*
2  * Copyright 2012 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
23  */
24 #include "priv.h"
25 #include "head.h"
26 
27 #include <nvif/class.h>
28 
29 static void
30 nv04_head_vblank_put(struct nvkm_head *head)
31 {
32 	struct nvkm_device *device = head->disp->engine.subdev.device;
33 	nvkm_wr32(device, 0x600140 + (head->id * 0x2000) , 0x00000000);
34 }
35 
36 static void
37 nv04_head_vblank_get(struct nvkm_head *head)
38 {
39 	struct nvkm_device *device = head->disp->engine.subdev.device;
40 	nvkm_wr32(device, 0x600140 + (head->id * 0x2000) , 0x00000001);
41 }
42 
43 static void
44 nv04_head_rgpos(struct nvkm_head *head, u16 *hline, u16 *vline)
45 {
46 	struct nvkm_device *device = head->disp->engine.subdev.device;
47 	u32 data = nvkm_rd32(device, 0x600868 + (head->id * 0x2000));
48 	*hline = (data & 0xffff0000) >> 16;
49 	*vline = (data & 0x0000ffff);
50 }
51 
52 static void
53 nv04_head_state(struct nvkm_head *head, struct nvkm_head_state *state)
54 {
55 	struct nvkm_device *device = head->disp->engine.subdev.device;
56 	const u32 hoff = head->id * 0x0200;
57 	state->vblanks = nvkm_rd32(device, 0x680800 + hoff) & 0x0000ffff;
58 	state->vtotal  = nvkm_rd32(device, 0x680804 + hoff) & 0x0000ffff;
59 	state->vblanke = state->vtotal - 1;
60 	state->hblanks = nvkm_rd32(device, 0x680820 + hoff) & 0x0000ffff;
61 	state->htotal  = nvkm_rd32(device, 0x680824 + hoff) & 0x0000ffff;
62 	state->hblanke = state->htotal - 1;
63 }
64 
65 static const struct nvkm_head_func
66 nv04_head = {
67 	.state = nv04_head_state,
68 	.rgpos = nv04_head_rgpos,
69 	.vblank_get = nv04_head_vblank_get,
70 	.vblank_put = nv04_head_vblank_put,
71 };
72 
73 static int
74 nv04_head_new(struct nvkm_disp *disp, int id)
75 {
76 	return nvkm_head_new_(&nv04_head, disp, id);
77 }
78 
79 static void
80 nv04_disp_intr(struct nvkm_disp *disp)
81 {
82 	struct nvkm_subdev *subdev = &disp->engine.subdev;
83 	struct nvkm_device *device = subdev->device;
84 	u32 crtc0 = nvkm_rd32(device, 0x600100);
85 	u32 crtc1 = nvkm_rd32(device, 0x602100);
86 	u32 pvideo;
87 
88 	if (crtc0 & 0x00000001) {
89 		nvkm_disp_vblank(disp, 0);
90 		nvkm_wr32(device, 0x600100, 0x00000001);
91 	}
92 
93 	if (crtc1 & 0x00000001) {
94 		nvkm_disp_vblank(disp, 1);
95 		nvkm_wr32(device, 0x602100, 0x00000001);
96 	}
97 
98 	if (device->chipset >= 0x10 && device->chipset <= 0x40) {
99 		pvideo = nvkm_rd32(device, 0x8100);
100 		if (pvideo & ~0x11)
101 			nvkm_info(subdev, "PVIDEO intr: %08x\n", pvideo);
102 		nvkm_wr32(device, 0x8100, pvideo);
103 	}
104 }
105 
106 static const struct nvkm_disp_func
107 nv04_disp = {
108 	.intr = nv04_disp_intr,
109 	.root = { 0, 0, NV04_DISP },
110 	.user = { {} },
111 };
112 
113 int
114 nv04_disp_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
115 	      struct nvkm_disp **pdisp)
116 {
117 	int ret, i;
118 
119 	ret = nvkm_disp_new_(&nv04_disp, device, type, inst, pdisp);
120 	if (ret)
121 		return ret;
122 
123 	for (i = 0; i < 2; i++) {
124 		ret = nv04_head_new(*pdisp, i);
125 		if (ret)
126 			return ret;
127 	}
128 
129 	return 0;
130 }
131