2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 #include <core/event.h>
28 #include <core/class.h>
30 struct nv04_disp_priv {
31 struct nouveau_disp base;
35 nv04_disp_scanoutpos(struct nouveau_object *object, u32 mthd,
38 struct nv04_disp_priv *priv = (void *)object->engine;
39 struct nv04_display_scanoutpos *args = data;
40 const int head = (mthd & NV04_DISP_MTHD_HEAD);
43 if (size < sizeof(*args))
46 args->vblanks = nv_rd32(priv, 0x680800 + (head * 0x2000)) & 0xffff;
47 args->vtotal = nv_rd32(priv, 0x680804 + (head * 0x2000)) & 0xffff;
48 args->vblanke = args->vtotal - 1;
50 args->hblanks = nv_rd32(priv, 0x680820 + (head * 0x2000)) & 0xffff;
51 args->htotal = nv_rd32(priv, 0x680824 + (head * 0x2000)) & 0xffff;
52 args->hblanke = args->htotal - 1;
55 * If output is vga instead of digital then vtotal/htotal is invalid
56 * so we have to give up and trigger the timestamping fallback in the
59 if (!args->vtotal || !args->htotal)
62 args->time[0] = ktime_to_ns(ktime_get());
63 line = nv_rd32(priv, 0x600868 + (head * 0x2000));
64 args->time[1] = ktime_to_ns(ktime_get());
65 args->hline = (line & 0xffff0000) >> 16;
66 args->vline = (line & 0x0000ffff);
70 #define HEAD_MTHD(n) (n), (n) + 0x01
72 static struct nouveau_omthds
73 nv04_disp_omthds[] = {
74 { HEAD_MTHD(NV04_DISP_SCANOUTPOS), nv04_disp_scanoutpos },
78 static struct nouveau_oclass
79 nv04_disp_sclass[] = {
80 { NV04_DISP_CLASS, &nouveau_object_ofuncs, nv04_disp_omthds },
84 /*******************************************************************************
85 * Display engine implementation
86 ******************************************************************************/
89 nv04_disp_vblank_enable(struct nouveau_event *event, int head)
91 nv_wr32(event->priv, 0x600140 + (head * 0x2000) , 0x00000001);
95 nv04_disp_vblank_disable(struct nouveau_event *event, int head)
97 nv_wr32(event->priv, 0x600140 + (head * 0x2000) , 0x00000000);
101 nv04_disp_intr(struct nouveau_subdev *subdev)
103 struct nv04_disp_priv *priv = (void *)subdev;
104 u32 crtc0 = nv_rd32(priv, 0x600100);
105 u32 crtc1 = nv_rd32(priv, 0x602100);
108 if (crtc0 & 0x00000001) {
109 nouveau_event_trigger(priv->base.vblank, 0);
110 nv_wr32(priv, 0x600100, 0x00000001);
113 if (crtc1 & 0x00000001) {
114 nouveau_event_trigger(priv->base.vblank, 1);
115 nv_wr32(priv, 0x602100, 0x00000001);
118 if (nv_device(priv)->chipset >= 0x10 &&
119 nv_device(priv)->chipset <= 0x40) {
120 pvideo = nv_rd32(priv, 0x8100);
122 nv_info(priv, "PVIDEO intr: %08x\n", pvideo);
123 nv_wr32(priv, 0x8100, pvideo);
128 nv04_disp_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
129 struct nouveau_oclass *oclass, void *data, u32 size,
130 struct nouveau_object **pobject)
132 struct nv04_disp_priv *priv;
135 ret = nouveau_disp_create(parent, engine, oclass, 2, "DISPLAY",
137 *pobject = nv_object(priv);
141 nv_engine(priv)->sclass = nv04_disp_sclass;
142 nv_subdev(priv)->intr = nv04_disp_intr;
143 priv->base.vblank->priv = priv;
144 priv->base.vblank->enable = nv04_disp_vblank_enable;
145 priv->base.vblank->disable = nv04_disp_vblank_disable;
149 struct nouveau_oclass *
150 nv04_disp_oclass = &(struct nouveau_disp_impl) {
151 .base.handle = NV_ENGINE(DISP, 0x04),
152 .base.ofuncs = &(struct nouveau_ofuncs) {
153 .ctor = nv04_disp_ctor,
154 .dtor = _nouveau_disp_dtor,
155 .init = _nouveau_disp_init,
156 .fini = _nouveau_disp_fini,