]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/nvkm/engine/disp/sorgf119.c
c3dbfd26ace895bc6125e71236072e5b2d63b9fd
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / nvkm / engine / disp / sorgf119.c
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 "ior.h"
25 #include "nv50.h"
26
27 #include <subdev/timer.h>
28
29 void
30 gf119_sor_dp_audio(struct nvkm_ior *sor, int head, bool enable)
31 {
32         struct nvkm_device *device = sor->disp->engine.subdev.device;
33         const u32 hoff = 0x800 * head;
34         const u32 data = 0x80000000 | (0x00000001 * enable);
35         const u32 mask = 0x8000000d;
36         nvkm_mask(device, 0x616618 + hoff, mask, data);
37         nvkm_msec(device, 2000,
38                 if (!(nvkm_rd32(device, 0x616618 + hoff) & 0x80000000))
39                         break;
40         );
41 }
42
43 void
44 gf119_sor_dp_vcpi(struct nvkm_output_dp *outp, int head, u8 slot,
45                   u8 slot_nr, u16 pbn, u16 aligned)
46 {
47         struct nvkm_device *device = outp->base.disp->engine.subdev.device;
48         const u32 hoff = head * 0x800;
49
50         nvkm_mask(device, 0x616588 + hoff, 0x00003f3f, (slot_nr << 8) | slot);
51         nvkm_mask(device, 0x61658c + hoff, 0xffffffff, (aligned << 16) | pbn);
52 }
53
54 void
55 gf119_sor_dp_drive(struct nvkm_ior *sor, int ln, int pc, int dc, int pe, int pu)
56 {
57         struct nvkm_device *device = sor->disp->engine.subdev.device;
58         const u32  loff = nv50_sor_link(sor);
59         const u32 shift = sor->func->dp.lanes[ln] * 8;
60         u32 data[4];
61
62         data[0] = nvkm_rd32(device, 0x61c118 + loff) & ~(0x000000ff << shift);
63         data[1] = nvkm_rd32(device, 0x61c120 + loff) & ~(0x000000ff << shift);
64         data[2] = nvkm_rd32(device, 0x61c130 + loff);
65         if ((data[2] & 0x0000ff00) < (pu << 8) || ln == 0)
66                 data[2] = (data[2] & ~0x0000ff00) | (pu << 8);
67         nvkm_wr32(device, 0x61c118 + loff, data[0] | (dc << shift));
68         nvkm_wr32(device, 0x61c120 + loff, data[1] | (pe << shift));
69         nvkm_wr32(device, 0x61c130 + loff, data[2]);
70         data[3] = nvkm_rd32(device, 0x61c13c + loff) & ~(0x000000ff << shift);
71         nvkm_wr32(device, 0x61c13c + loff, data[3] | (pc << shift));
72 }
73
74 void
75 gf119_sor_dp_pattern(struct nvkm_ior *sor, int pattern)
76 {
77         struct nvkm_device *device = sor->disp->engine.subdev.device;
78         const u32 soff = nv50_ior_base(sor);
79         nvkm_mask(device, 0x61c110 + soff, 0x0f0f0f0f, 0x01010101 * pattern);
80 }
81
82 int
83 gf119_sor_dp_links(struct nvkm_ior *sor, struct nvkm_i2c_aux *aux)
84 {
85         struct nvkm_device *device = sor->disp->engine.subdev.device;
86         const u32 soff = nv50_ior_base(sor);
87         const u32 loff = nv50_sor_link(sor);
88         u32 dpctrl = 0x00000000;
89         u32 clksor = 0x00000000;
90
91         clksor |= sor->dp.bw << 18;
92         dpctrl |= ((1 << sor->dp.nr) - 1) << 16;
93         if (sor->dp.mst)
94                 dpctrl |= 0x40000000;
95         if (sor->dp.ef)
96                 dpctrl |= 0x00004000;
97
98         nvkm_mask(device, 0x612300 + soff, 0x007c0000, clksor);
99         nvkm_mask(device, 0x61c10c + loff, 0x401f4000, dpctrl);
100         return 0;
101 }
102
103 static const struct nvkm_output_dp_func
104 gf119_sor_dp_func = {
105         .vcpi = gf119_sor_dp_vcpi,
106 };
107
108 int
109 gf119_sor_dp_new(struct nvkm_disp *disp, int index,
110                  struct dcb_output *dcbE, struct nvkm_output **poutp)
111 {
112         return nvkm_output_dp_new_(&gf119_sor_dp_func, disp, index, dcbE, poutp);
113 }
114
115 void
116 gf119_sor_state(struct nvkm_ior *sor, struct nvkm_ior_state *state)
117 {
118         struct nvkm_device *device = sor->disp->engine.subdev.device;
119         const u32 coff = (state == &sor->asy) * 0x20000 + sor->id * 0x20;
120         u32 ctrl = nvkm_rd32(device, 0x640200 + coff);
121
122         state->proto_evo = (ctrl & 0x00000f00) >> 8;
123         switch (state->proto_evo) {
124         case 0: state->proto = LVDS; state->link = 1; break;
125         case 1: state->proto = TMDS; state->link = 1; break;
126         case 2: state->proto = TMDS; state->link = 2; break;
127         case 5: state->proto = TMDS; state->link = 3; break;
128         case 8: state->proto =   DP; state->link = 1; break;
129         case 9: state->proto =   DP; state->link = 2; break;
130         default:
131                 state->proto = UNKNOWN;
132                 break;
133         }
134
135         state->head = ctrl & 0x0000000f;
136 }
137
138 static const struct nvkm_ior_func
139 gf119_sor = {
140         .state = gf119_sor_state,
141         .power = nv50_sor_power,
142         .hdmi = {
143                 .ctrl = gf119_hdmi_ctrl,
144         },
145         .dp = {
146                 .lanes = { 2, 1, 0, 3 },
147                 .links = gf119_sor_dp_links,
148                 .power = g94_sor_dp_power,
149                 .pattern = gf119_sor_dp_pattern,
150                 .audio = gf119_sor_dp_audio,
151         },
152         .hda = {
153                 .hpd = gf119_hda_hpd,
154                 .eld = gf119_hda_eld,
155         },
156 };
157
158 int
159 gf119_sor_new(struct nvkm_disp *disp, int id)
160 {
161         return nvkm_ior_new_(&gf119_sor, disp, SOR, id);
162 }