Ben Skeggs | 56d237d | 2014-05-19 14:54:33 +1000 | [diff] [blame] | 1 | /* |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2 | * Copyright 2011 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 | */ |
Ben Skeggs | 1590700 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 24 | #include "disp.h" |
| 25 | #include "atom.h" |
| 26 | #include "core.h" |
| 27 | #include "head.h" |
| 28 | #include "wndw.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 29 | |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 30 | #include <linux/dma-mapping.h> |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 31 | #include <linux/hdmi.h> |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 32 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 33 | #include <drm/drmP.h> |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 34 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drm_crtc_helper.h> |
Ben Skeggs | 4874322 | 2014-05-31 01:48:06 +1000 | [diff] [blame] | 36 | #include <drm/drm_dp_helper.h> |
Daniel Vetter | b516a9e | 2015-12-04 09:45:43 +0100 | [diff] [blame] | 37 | #include <drm/drm_fb_helper.h> |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 38 | #include <drm/drm_plane_helper.h> |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 39 | #include <drm/drm_edid.h> |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 40 | |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 41 | #include <nvif/class.h> |
Ben Skeggs | 845f272 | 2015-11-08 12:16:40 +1000 | [diff] [blame] | 42 | #include <nvif/cl0002.h> |
Ben Skeggs | 7568b10 | 2015-11-08 10:44:19 +1000 | [diff] [blame] | 43 | #include <nvif/cl5070.h> |
Ben Skeggs | 7568b10 | 2015-11-08 10:44:19 +1000 | [diff] [blame] | 44 | #include <nvif/cl507d.h> |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 45 | #include <nvif/event.h> |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 46 | |
Ben Skeggs | 4dc2813 | 2016-05-20 09:22:55 +1000 | [diff] [blame] | 47 | #include "nouveau_drv.h" |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 48 | #include "nouveau_dma.h" |
| 49 | #include "nouveau_gem.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 50 | #include "nouveau_connector.h" |
| 51 | #include "nouveau_encoder.h" |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 52 | #include "nouveau_fence.h" |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 53 | #include "nouveau_fbcon.h" |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 54 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 55 | /****************************************************************************** |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 56 | * Atomic state |
| 57 | *****************************************************************************/ |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 58 | |
| 59 | struct nv50_outp_atom { |
| 60 | struct list_head head; |
| 61 | |
| 62 | struct drm_encoder *encoder; |
| 63 | bool flush_disable; |
| 64 | |
| 65 | union { |
| 66 | struct { |
| 67 | bool ctrl:1; |
| 68 | }; |
| 69 | u8 mask; |
| 70 | } clr; |
| 71 | |
| 72 | union { |
| 73 | struct { |
| 74 | bool ctrl:1; |
| 75 | }; |
| 76 | u8 mask; |
| 77 | } set; |
| 78 | }; |
| 79 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 80 | /****************************************************************************** |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 81 | * EVO channel |
| 82 | *****************************************************************************/ |
| 83 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 84 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 85 | nv50_chan_create(struct nvif_device *device, struct nvif_object *disp, |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 86 | const s32 *oclass, u8 head, void *data, u32 size, |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 87 | struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 88 | { |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 89 | struct nvif_sclass *sclass; |
| 90 | int ret, i, n; |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 91 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 92 | chan->device = device; |
| 93 | |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 94 | ret = n = nvif_object_sclass_get(disp, &sclass); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 95 | if (ret < 0) |
| 96 | return ret; |
| 97 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 98 | while (oclass[0]) { |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 99 | for (i = 0; i < n; i++) { |
| 100 | if (sclass[i].oclass == oclass[0]) { |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 101 | ret = nvif_object_init(disp, 0, oclass[0], |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 102 | data, size, &chan->user); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 103 | if (ret == 0) |
Ben Skeggs | 0132605 | 2017-11-01 03:56:19 +1000 | [diff] [blame] | 104 | nvif_object_map(&chan->user, NULL, 0); |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 105 | nvif_object_sclass_put(&sclass); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 106 | return ret; |
| 107 | } |
Ben Skeggs | b76f152 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 108 | } |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 109 | oclass++; |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 110 | } |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 111 | |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 112 | nvif_object_sclass_put(&sclass); |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 113 | return -ENOSYS; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | static void |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 117 | nv50_chan_destroy(struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 118 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 119 | nvif_object_fini(&chan->user); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /****************************************************************************** |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 123 | * DMA EVO channel |
| 124 | *****************************************************************************/ |
| 125 | |
Ben Skeggs | 1590700 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 126 | void |
Ben Skeggs | f565047 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 127 | nv50_dmac_destroy(struct nv50_dmac *dmac) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 128 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 129 | nvif_object_fini(&dmac->vram); |
| 130 | nvif_object_fini(&dmac->sync); |
| 131 | |
| 132 | nv50_chan_destroy(&dmac->base); |
| 133 | |
Ben Skeggs | f565047 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 134 | nvif_mem_fini(&dmac->push); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 135 | } |
| 136 | |
Ben Skeggs | 1590700 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 137 | int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 138 | nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp, |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 139 | const s32 *oclass, u8 head, void *data, u32 size, u64 syncbuf, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 140 | struct nv50_dmac *dmac) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 141 | { |
Ben Skeggs | f565047 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 142 | struct nouveau_cli *cli = (void *)device->object.client; |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 143 | struct nv50_disp_core_channel_dma_v0 *args = data; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 144 | int ret; |
| 145 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 146 | mutex_init(&dmac->lock); |
| 147 | |
Ben Skeggs | f565047 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 148 | ret = nvif_mem_init_map(&cli->mmu, NVIF_MEM_COHERENT, 0x1000, |
| 149 | &dmac->push); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 150 | if (ret) |
| 151 | return ret; |
| 152 | |
Ben Skeggs | f565047 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 153 | dmac->ptr = dmac->push.object.map.ptr; |
| 154 | |
| 155 | args->pushbuf = nvif_handle(&dmac->push.object); |
Ben Skeggs | bf81df9 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 156 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 157 | ret = nv50_chan_create(device, disp, oclass, head, data, size, |
| 158 | &dmac->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 159 | if (ret) |
| 160 | return ret; |
| 161 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 162 | ret = nvif_object_init(&dmac->base.user, 0xf0000000, NV_DMA_IN_MEMORY, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 163 | &(struct nv_dma_v0) { |
| 164 | .target = NV_DMA_V0_TARGET_VRAM, |
| 165 | .access = NV_DMA_V0_ACCESS_RDWR, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 166 | .start = syncbuf + 0x0000, |
| 167 | .limit = syncbuf + 0x0fff, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 168 | }, sizeof(struct nv_dma_v0), |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 169 | &dmac->sync); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 170 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 171 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 172 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 173 | ret = nvif_object_init(&dmac->base.user, 0xf0000001, NV_DMA_IN_MEMORY, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 174 | &(struct nv_dma_v0) { |
| 175 | .target = NV_DMA_V0_TARGET_VRAM, |
| 176 | .access = NV_DMA_V0_ACCESS_RDWR, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 177 | .start = 0, |
Ben Skeggs | f392ec4 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 178 | .limit = device->info.ram_user - 1, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 179 | }, sizeof(struct nv_dma_v0), |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 180 | &dmac->vram); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 181 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 182 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 183 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 184 | return ret; |
| 185 | } |
| 186 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 187 | /****************************************************************************** |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 188 | * EVO channel helpers |
| 189 | *****************************************************************************/ |
Ben Skeggs | 1590700 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 190 | u32 * |
| 191 | evo_wait(struct nv50_dmac *evoc, int nr) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 192 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 193 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 194 | struct nvif_device *device = dmac->base.device; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 195 | u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 196 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 197 | mutex_lock(&dmac->lock); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 198 | if (put + nr >= (PAGE_SIZE / 4) - 8) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 199 | dmac->ptr[put] = 0x20000000; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 200 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 201 | nvif_wr32(&dmac->base.user, 0x0000, 0x00000000); |
Ben Skeggs | 5444204 | 2015-08-20 14:54:11 +1000 | [diff] [blame] | 202 | if (nvif_msec(device, 2000, |
| 203 | if (!nvif_rd32(&dmac->base.user, 0x0004)) |
| 204 | break; |
| 205 | ) < 0) { |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 206 | mutex_unlock(&dmac->lock); |
Joe Perches | 8dfe162 | 2017-02-28 04:55:54 -0800 | [diff] [blame] | 207 | pr_err("nouveau: evo channel stalled\n"); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 208 | return NULL; |
| 209 | } |
| 210 | |
| 211 | put = 0; |
| 212 | } |
| 213 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 214 | return dmac->ptr + put; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 215 | } |
| 216 | |
Ben Skeggs | 1590700 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 217 | void |
| 218 | evo_kick(u32 *push, struct nv50_dmac *evoc) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 219 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 220 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 221 | nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2); |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 222 | mutex_unlock(&dmac->lock); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 223 | } |
| 224 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 225 | /****************************************************************************** |
Ben Skeggs | d92c8ad | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 226 | * Output path helpers |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 227 | *****************************************************************************/ |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 228 | static void |
| 229 | nv50_outp_release(struct nouveau_encoder *nv_encoder) |
| 230 | { |
| 231 | struct nv50_disp *disp = nv50_disp(nv_encoder->base.base.dev); |
| 232 | struct { |
| 233 | struct nv50_disp_mthd_v1 base; |
| 234 | } args = { |
| 235 | .base.version = 1, |
| 236 | .base.method = NV50_DISP_MTHD_V1_RELEASE, |
| 237 | .base.hasht = nv_encoder->dcb->hasht, |
| 238 | .base.hashm = nv_encoder->dcb->hashm, |
| 239 | }; |
| 240 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 241 | nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 242 | nv_encoder->or = -1; |
| 243 | nv_encoder->link = 0; |
| 244 | } |
| 245 | |
| 246 | static int |
| 247 | nv50_outp_acquire(struct nouveau_encoder *nv_encoder) |
| 248 | { |
| 249 | struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); |
| 250 | struct nv50_disp *disp = nv50_disp(drm->dev); |
| 251 | struct { |
| 252 | struct nv50_disp_mthd_v1 base; |
| 253 | struct nv50_disp_acquire_v0 info; |
| 254 | } args = { |
| 255 | .base.version = 1, |
| 256 | .base.method = NV50_DISP_MTHD_V1_ACQUIRE, |
| 257 | .base.hasht = nv_encoder->dcb->hasht, |
| 258 | .base.hashm = nv_encoder->dcb->hashm, |
| 259 | }; |
| 260 | int ret; |
| 261 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 262 | ret = nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 263 | if (ret) { |
| 264 | NV_ERROR(drm, "error acquiring output path: %d\n", ret); |
| 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | nv_encoder->or = args.info.or; |
| 269 | nv_encoder->link = args.info.link; |
| 270 | return 0; |
| 271 | } |
| 272 | |
Ben Skeggs | d92c8ad | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 273 | static int |
| 274 | nv50_outp_atomic_check_view(struct drm_encoder *encoder, |
| 275 | struct drm_crtc_state *crtc_state, |
| 276 | struct drm_connector_state *conn_state, |
| 277 | struct drm_display_mode *native_mode) |
| 278 | { |
| 279 | struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode; |
| 280 | struct drm_display_mode *mode = &crtc_state->mode; |
| 281 | struct drm_connector *connector = conn_state->connector; |
| 282 | struct nouveau_conn_atom *asyc = nouveau_conn_atom(conn_state); |
| 283 | struct nouveau_drm *drm = nouveau_drm(encoder->dev); |
| 284 | |
| 285 | NV_ATOMIC(drm, "%s atomic_check\n", encoder->name); |
| 286 | asyc->scaler.full = false; |
| 287 | if (!native_mode) |
| 288 | return 0; |
| 289 | |
| 290 | if (asyc->scaler.mode == DRM_MODE_SCALE_NONE) { |
| 291 | switch (connector->connector_type) { |
| 292 | case DRM_MODE_CONNECTOR_LVDS: |
| 293 | case DRM_MODE_CONNECTOR_eDP: |
| 294 | /* Force use of scaler for non-EDID modes. */ |
| 295 | if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER) |
| 296 | break; |
| 297 | mode = native_mode; |
| 298 | asyc->scaler.full = true; |
| 299 | break; |
| 300 | default: |
| 301 | break; |
| 302 | } |
| 303 | } else { |
| 304 | mode = native_mode; |
| 305 | } |
| 306 | |
| 307 | if (!drm_mode_equal(adjusted_mode, mode)) { |
| 308 | drm_mode_copy(adjusted_mode, mode); |
| 309 | crtc_state->mode_changed = true; |
| 310 | } |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 315 | static int |
| 316 | nv50_outp_atomic_check(struct drm_encoder *encoder, |
| 317 | struct drm_crtc_state *crtc_state, |
| 318 | struct drm_connector_state *conn_state) |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 319 | { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 320 | struct nouveau_connector *nv_connector = |
| 321 | nouveau_connector(conn_state->connector); |
| 322 | return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state, |
| 323 | nv_connector->native_mode); |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 327 | * DAC |
| 328 | *****************************************************************************/ |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 329 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 330 | nv50_dac_disable(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 331 | { |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 332 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 333 | struct nv50_core *core = nv50_disp(encoder->dev)->core; |
| 334 | if (nv_encoder->crtc) |
| 335 | core->func->dac->ctrl(core, nv_encoder->or, 0x00000000, NULL); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 336 | nv_encoder->crtc = NULL; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 337 | nv50_outp_release(nv_encoder); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 341 | nv50_dac_enable(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 342 | { |
| 343 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 344 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 345 | struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state); |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 346 | struct nv50_core *core = nv50_disp(encoder->dev)->core; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 347 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 348 | nv50_outp_acquire(nv_encoder); |
| 349 | |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 350 | core->func->dac->ctrl(core, nv_encoder->or, 1 << nv_crtc->index, asyh); |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 351 | asyh->or.depth = 0; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 352 | |
| 353 | nv_encoder->crtc = encoder->crtc; |
| 354 | } |
| 355 | |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 356 | static enum drm_connector_status |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 357 | nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 358 | { |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 359 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 360 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 361 | struct { |
| 362 | struct nv50_disp_mthd_v1 base; |
| 363 | struct nv50_disp_dac_load_v0 load; |
| 364 | } args = { |
| 365 | .base.version = 1, |
| 366 | .base.method = NV50_DISP_MTHD_V1_DAC_LOAD, |
| 367 | .base.hasht = nv_encoder->dcb->hasht, |
| 368 | .base.hashm = nv_encoder->dcb->hashm, |
| 369 | }; |
| 370 | int ret; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 371 | |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 372 | args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval; |
| 373 | if (args.load.data == 0) |
| 374 | args.load.data = 340; |
| 375 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 376 | ret = nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 377 | if (ret || !args.load.load) |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 378 | return connector_status_disconnected; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 379 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 380 | return connector_status_connected; |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 381 | } |
| 382 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 383 | static const struct drm_encoder_helper_funcs |
| 384 | nv50_dac_help = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 385 | .atomic_check = nv50_outp_atomic_check, |
| 386 | .enable = nv50_dac_enable, |
| 387 | .disable = nv50_dac_disable, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 388 | .detect = nv50_dac_detect |
| 389 | }; |
| 390 | |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 391 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 392 | nv50_dac_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 393 | { |
| 394 | drm_encoder_cleanup(encoder); |
| 395 | kfree(encoder); |
| 396 | } |
| 397 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 398 | static const struct drm_encoder_funcs |
| 399 | nv50_dac_func = { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 400 | .destroy = nv50_dac_destroy, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 404 | nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 405 | { |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 406 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 407 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 408 | struct nvkm_i2c_bus *bus; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 409 | struct nouveau_encoder *nv_encoder; |
| 410 | struct drm_encoder *encoder; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 411 | int type = DRM_MODE_ENCODER_DAC; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 412 | |
| 413 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 414 | if (!nv_encoder) |
| 415 | return -ENOMEM; |
| 416 | nv_encoder->dcb = dcbe; |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 417 | |
| 418 | bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index); |
| 419 | if (bus) |
| 420 | nv_encoder->i2c = &bus->i2c; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 421 | |
| 422 | encoder = to_drm_encoder(nv_encoder); |
| 423 | encoder->possible_crtcs = dcbe->heads; |
| 424 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 425 | drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type, |
| 426 | "dac-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 427 | drm_encoder_helper_add(encoder, &nv50_dac_help); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 428 | |
| 429 | drm_mode_connector_attach_encoder(connector, encoder); |
| 430 | return 0; |
| 431 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 432 | |
| 433 | /****************************************************************************** |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 434 | * Audio |
| 435 | *****************************************************************************/ |
| 436 | static void |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 437 | nv50_audio_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc) |
| 438 | { |
| 439 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 440 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
| 441 | struct { |
| 442 | struct nv50_disp_mthd_v1 base; |
| 443 | struct nv50_disp_sor_hda_eld_v0 eld; |
| 444 | } args = { |
| 445 | .base.version = 1, |
| 446 | .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD, |
| 447 | .base.hasht = nv_encoder->dcb->hasht, |
| 448 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 449 | (0x0100 << nv_crtc->index), |
| 450 | }; |
| 451 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 452 | nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | static void |
| 456 | nv50_audio_enable(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 457 | { |
| 458 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 459 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 460 | struct nouveau_connector *nv_connector; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 461 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | d889c52 | 2014-09-15 21:11:51 +1000 | [diff] [blame] | 462 | struct __packed { |
| 463 | struct { |
| 464 | struct nv50_disp_mthd_v1 mthd; |
| 465 | struct nv50_disp_sor_hda_eld_v0 eld; |
| 466 | } base; |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 467 | u8 data[sizeof(nv_connector->base.eld)]; |
| 468 | } args = { |
Ben Skeggs | d889c52 | 2014-09-15 21:11:51 +1000 | [diff] [blame] | 469 | .base.mthd.version = 1, |
| 470 | .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD, |
| 471 | .base.mthd.hasht = nv_encoder->dcb->hasht, |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 472 | .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 473 | (0x0100 << nv_crtc->index), |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 474 | }; |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 475 | |
| 476 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 477 | if (!drm_detect_monitor_audio(nv_connector->edid)) |
| 478 | return; |
| 479 | |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 480 | memcpy(args.data, nv_connector->base.eld, sizeof(args.data)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 481 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 482 | nvif_mthd(&disp->disp->object, 0, &args, |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 483 | sizeof(args.base) + drm_eld_size(args.data)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 484 | } |
| 485 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 486 | /****************************************************************************** |
| 487 | * HDMI |
| 488 | *****************************************************************************/ |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 489 | static void |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 490 | nv50_hdmi_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 491 | { |
| 492 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 493 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 494 | struct { |
| 495 | struct nv50_disp_mthd_v1 base; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 496 | struct nv50_disp_sor_hdmi_pwr_v0 pwr; |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 497 | } args = { |
| 498 | .base.version = 1, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 499 | .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR, |
| 500 | .base.hasht = nv_encoder->dcb->hasht, |
| 501 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 502 | (0x0100 << nv_crtc->index), |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 503 | }; |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 504 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 505 | nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 506 | } |
| 507 | |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 508 | static void |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 509 | nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 510 | { |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 511 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 512 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 513 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 514 | struct { |
| 515 | struct nv50_disp_mthd_v1 base; |
| 516 | struct nv50_disp_sor_hdmi_pwr_v0 pwr; |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 517 | u8 infoframes[2 * 17]; /* two frames, up to 17 bytes each */ |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 518 | } args = { |
| 519 | .base.version = 1, |
| 520 | .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR, |
| 521 | .base.hasht = nv_encoder->dcb->hasht, |
| 522 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 523 | (0x0100 << nv_crtc->index), |
| 524 | .pwr.state = 1, |
| 525 | .pwr.rekey = 56, /* binary driver, and tegra, constant */ |
| 526 | }; |
| 527 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 528 | u32 max_ac_packet; |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 529 | union hdmi_infoframe avi_frame; |
| 530 | union hdmi_infoframe vendor_frame; |
| 531 | int ret; |
| 532 | int size; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 533 | |
| 534 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 535 | if (!drm_detect_hdmi_monitor(nv_connector->edid)) |
| 536 | return; |
| 537 | |
Shashank Sharma | 0c1f528 | 2017-07-13 21:03:07 +0530 | [diff] [blame] | 538 | ret = drm_hdmi_avi_infoframe_from_display_mode(&avi_frame.avi, mode, |
| 539 | false); |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 540 | if (!ret) { |
| 541 | /* We have an AVI InfoFrame, populate it to the display */ |
| 542 | args.pwr.avi_infoframe_length |
| 543 | = hdmi_infoframe_pack(&avi_frame, args.infoframes, 17); |
| 544 | } |
| 545 | |
Ville Syrjälä | f1781e9 | 2017-11-13 19:04:19 +0200 | [diff] [blame] | 546 | ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi, |
| 547 | &nv_connector->base, mode); |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 548 | if (!ret) { |
| 549 | /* We have a Vendor InfoFrame, populate it to the display */ |
| 550 | args.pwr.vendor_infoframe_length |
| 551 | = hdmi_infoframe_pack(&vendor_frame, |
| 552 | args.infoframes |
| 553 | + args.pwr.avi_infoframe_length, |
| 554 | 17); |
| 555 | } |
| 556 | |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 557 | max_ac_packet = mode->htotal - mode->hdisplay; |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 558 | max_ac_packet -= args.pwr.rekey; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 559 | max_ac_packet -= 18; /* constant from tegra */ |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 560 | args.pwr.max_ac_packet = max_ac_packet / 32; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 561 | |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 562 | size = sizeof(args.base) |
| 563 | + sizeof(args.pwr) |
| 564 | + args.pwr.avi_infoframe_length |
| 565 | + args.pwr.vendor_infoframe_length; |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 566 | nvif_mthd(&disp->disp->object, 0, &args, size); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 567 | nv50_audio_enable(encoder, mode); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /****************************************************************************** |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 571 | * MST |
| 572 | *****************************************************************************/ |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 573 | #define nv50_mstm(p) container_of((p), struct nv50_mstm, mgr) |
| 574 | #define nv50_mstc(p) container_of((p), struct nv50_mstc, connector) |
| 575 | #define nv50_msto(p) container_of((p), struct nv50_msto, encoder) |
| 576 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 577 | struct nv50_mstm { |
| 578 | struct nouveau_encoder *outp; |
| 579 | |
| 580 | struct drm_dp_mst_topology_mgr mgr; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 581 | struct nv50_msto *msto[4]; |
| 582 | |
| 583 | bool modified; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 584 | bool disabled; |
| 585 | int links; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 586 | }; |
| 587 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 588 | struct nv50_mstc { |
| 589 | struct nv50_mstm *mstm; |
| 590 | struct drm_dp_mst_port *port; |
| 591 | struct drm_connector connector; |
| 592 | |
| 593 | struct drm_display_mode *native; |
| 594 | struct edid *edid; |
| 595 | |
| 596 | int pbn; |
| 597 | }; |
| 598 | |
| 599 | struct nv50_msto { |
| 600 | struct drm_encoder encoder; |
| 601 | |
| 602 | struct nv50_head *head; |
| 603 | struct nv50_mstc *mstc; |
| 604 | bool disabled; |
| 605 | }; |
| 606 | |
| 607 | static struct drm_dp_payload * |
| 608 | nv50_msto_payload(struct nv50_msto *msto) |
| 609 | { |
| 610 | struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev); |
| 611 | struct nv50_mstc *mstc = msto->mstc; |
| 612 | struct nv50_mstm *mstm = mstc->mstm; |
| 613 | int vcpi = mstc->port->vcpi.vcpi, i; |
| 614 | |
| 615 | NV_ATOMIC(drm, "%s: vcpi %d\n", msto->encoder.name, vcpi); |
| 616 | for (i = 0; i < mstm->mgr.max_payloads; i++) { |
| 617 | struct drm_dp_payload *payload = &mstm->mgr.payloads[i]; |
| 618 | NV_ATOMIC(drm, "%s: %d: vcpi %d start 0x%02x slots 0x%02x\n", |
| 619 | mstm->outp->base.base.name, i, payload->vcpi, |
| 620 | payload->start_slot, payload->num_slots); |
| 621 | } |
| 622 | |
| 623 | for (i = 0; i < mstm->mgr.max_payloads; i++) { |
| 624 | struct drm_dp_payload *payload = &mstm->mgr.payloads[i]; |
| 625 | if (payload->vcpi == vcpi) |
| 626 | return payload; |
| 627 | } |
| 628 | |
| 629 | return NULL; |
| 630 | } |
| 631 | |
| 632 | static void |
| 633 | nv50_msto_cleanup(struct nv50_msto *msto) |
| 634 | { |
| 635 | struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev); |
| 636 | struct nv50_mstc *mstc = msto->mstc; |
| 637 | struct nv50_mstm *mstm = mstc->mstm; |
| 638 | |
| 639 | NV_ATOMIC(drm, "%s: msto cleanup\n", msto->encoder.name); |
| 640 | if (mstc->port && mstc->port->vcpi.vcpi > 0 && !nv50_msto_payload(msto)) |
| 641 | drm_dp_mst_deallocate_vcpi(&mstm->mgr, mstc->port); |
| 642 | if (msto->disabled) { |
| 643 | msto->mstc = NULL; |
| 644 | msto->head = NULL; |
| 645 | msto->disabled = false; |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | static void |
| 650 | nv50_msto_prepare(struct nv50_msto *msto) |
| 651 | { |
| 652 | struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev); |
| 653 | struct nv50_mstc *mstc = msto->mstc; |
| 654 | struct nv50_mstm *mstm = mstc->mstm; |
| 655 | struct { |
| 656 | struct nv50_disp_mthd_v1 base; |
| 657 | struct nv50_disp_sor_dp_mst_vcpi_v0 vcpi; |
| 658 | } args = { |
| 659 | .base.version = 1, |
| 660 | .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_VCPI, |
| 661 | .base.hasht = mstm->outp->dcb->hasht, |
| 662 | .base.hashm = (0xf0ff & mstm->outp->dcb->hashm) | |
| 663 | (0x0100 << msto->head->base.index), |
| 664 | }; |
| 665 | |
| 666 | NV_ATOMIC(drm, "%s: msto prepare\n", msto->encoder.name); |
| 667 | if (mstc->port && mstc->port->vcpi.vcpi > 0) { |
| 668 | struct drm_dp_payload *payload = nv50_msto_payload(msto); |
| 669 | if (payload) { |
| 670 | args.vcpi.start_slot = payload->start_slot; |
| 671 | args.vcpi.num_slots = payload->num_slots; |
| 672 | args.vcpi.pbn = mstc->port->vcpi.pbn; |
| 673 | args.vcpi.aligned_pbn = mstc->port->vcpi.aligned_pbn; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | NV_ATOMIC(drm, "%s: %s: %02x %02x %04x %04x\n", |
| 678 | msto->encoder.name, msto->head->base.base.name, |
| 679 | args.vcpi.start_slot, args.vcpi.num_slots, |
| 680 | args.vcpi.pbn, args.vcpi.aligned_pbn); |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 681 | nvif_mthd(&drm->display->disp.object, 0, &args, sizeof(args)); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | static int |
| 685 | nv50_msto_atomic_check(struct drm_encoder *encoder, |
| 686 | struct drm_crtc_state *crtc_state, |
| 687 | struct drm_connector_state *conn_state) |
| 688 | { |
| 689 | struct nv50_mstc *mstc = nv50_mstc(conn_state->connector); |
| 690 | struct nv50_mstm *mstm = mstc->mstm; |
| 691 | int bpp = conn_state->connector->display_info.bpc * 3; |
| 692 | int slots; |
| 693 | |
| 694 | mstc->pbn = drm_dp_calc_pbn_mode(crtc_state->adjusted_mode.clock, bpp); |
| 695 | |
| 696 | slots = drm_dp_find_vcpi_slots(&mstm->mgr, mstc->pbn); |
| 697 | if (slots < 0) |
| 698 | return slots; |
| 699 | |
| 700 | return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state, |
| 701 | mstc->native); |
| 702 | } |
| 703 | |
| 704 | static void |
| 705 | nv50_msto_enable(struct drm_encoder *encoder) |
| 706 | { |
| 707 | struct nv50_head *head = nv50_head(encoder->crtc); |
| 708 | struct nv50_msto *msto = nv50_msto(encoder); |
| 709 | struct nv50_mstc *mstc = NULL; |
| 710 | struct nv50_mstm *mstm = NULL; |
| 711 | struct drm_connector *connector; |
Gustavo Padovan | 875dd62 | 2017-05-11 16:10:46 -0300 | [diff] [blame] | 712 | struct drm_connector_list_iter conn_iter; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 713 | u8 proto, depth; |
| 714 | int slots; |
| 715 | bool r; |
| 716 | |
Gustavo Padovan | 875dd62 | 2017-05-11 16:10:46 -0300 | [diff] [blame] | 717 | drm_connector_list_iter_begin(encoder->dev, &conn_iter); |
| 718 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 719 | if (connector->state->best_encoder == &msto->encoder) { |
| 720 | mstc = nv50_mstc(connector); |
| 721 | mstm = mstc->mstm; |
| 722 | break; |
| 723 | } |
| 724 | } |
Gustavo Padovan | 875dd62 | 2017-05-11 16:10:46 -0300 | [diff] [blame] | 725 | drm_connector_list_iter_end(&conn_iter); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 726 | |
| 727 | if (WARN_ON(!mstc)) |
| 728 | return; |
| 729 | |
Pandiyan, Dhinakaran | 1e797f5 | 2017-03-16 00:10:26 -0700 | [diff] [blame] | 730 | slots = drm_dp_find_vcpi_slots(&mstm->mgr, mstc->pbn); |
| 731 | r = drm_dp_mst_allocate_vcpi(&mstm->mgr, mstc->port, mstc->pbn, slots); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 732 | WARN_ON(!r); |
| 733 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 734 | if (!mstm->links++) |
| 735 | nv50_outp_acquire(mstm->outp); |
| 736 | |
| 737 | if (mstm->outp->link & 1) |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 738 | proto = 0x8; |
| 739 | else |
| 740 | proto = 0x9; |
| 741 | |
| 742 | switch (mstc->connector.display_info.bpc) { |
| 743 | case 6: depth = 0x2; break; |
| 744 | case 8: depth = 0x5; break; |
| 745 | case 10: |
| 746 | default: depth = 0x6; break; |
| 747 | } |
| 748 | |
| 749 | mstm->outp->update(mstm->outp, head->base.index, |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 750 | nv50_head_atom(head->base.base.state), proto, depth); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 751 | |
| 752 | msto->head = head; |
| 753 | msto->mstc = mstc; |
| 754 | mstm->modified = true; |
| 755 | } |
| 756 | |
| 757 | static void |
| 758 | nv50_msto_disable(struct drm_encoder *encoder) |
| 759 | { |
| 760 | struct nv50_msto *msto = nv50_msto(encoder); |
| 761 | struct nv50_mstc *mstc = msto->mstc; |
| 762 | struct nv50_mstm *mstm = mstc->mstm; |
| 763 | |
| 764 | if (mstc->port) |
| 765 | drm_dp_mst_reset_vcpi_slots(&mstm->mgr, mstc->port); |
| 766 | |
| 767 | mstm->outp->update(mstm->outp, msto->head->base.index, NULL, 0, 0); |
| 768 | mstm->modified = true; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 769 | if (!--mstm->links) |
| 770 | mstm->disabled = true; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 771 | msto->disabled = true; |
| 772 | } |
| 773 | |
| 774 | static const struct drm_encoder_helper_funcs |
| 775 | nv50_msto_help = { |
| 776 | .disable = nv50_msto_disable, |
| 777 | .enable = nv50_msto_enable, |
| 778 | .atomic_check = nv50_msto_atomic_check, |
| 779 | }; |
| 780 | |
| 781 | static void |
| 782 | nv50_msto_destroy(struct drm_encoder *encoder) |
| 783 | { |
| 784 | struct nv50_msto *msto = nv50_msto(encoder); |
| 785 | drm_encoder_cleanup(&msto->encoder); |
| 786 | kfree(msto); |
| 787 | } |
| 788 | |
| 789 | static const struct drm_encoder_funcs |
| 790 | nv50_msto = { |
| 791 | .destroy = nv50_msto_destroy, |
| 792 | }; |
| 793 | |
| 794 | static int |
| 795 | nv50_msto_new(struct drm_device *dev, u32 heads, const char *name, int id, |
| 796 | struct nv50_msto **pmsto) |
| 797 | { |
| 798 | struct nv50_msto *msto; |
| 799 | int ret; |
| 800 | |
| 801 | if (!(msto = *pmsto = kzalloc(sizeof(*msto), GFP_KERNEL))) |
| 802 | return -ENOMEM; |
| 803 | |
| 804 | ret = drm_encoder_init(dev, &msto->encoder, &nv50_msto, |
| 805 | DRM_MODE_ENCODER_DPMST, "%s-mst-%d", name, id); |
| 806 | if (ret) { |
| 807 | kfree(*pmsto); |
| 808 | *pmsto = NULL; |
| 809 | return ret; |
| 810 | } |
| 811 | |
| 812 | drm_encoder_helper_add(&msto->encoder, &nv50_msto_help); |
| 813 | msto->encoder.possible_crtcs = heads; |
| 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | static struct drm_encoder * |
| 818 | nv50_mstc_atomic_best_encoder(struct drm_connector *connector, |
| 819 | struct drm_connector_state *connector_state) |
| 820 | { |
| 821 | struct nv50_head *head = nv50_head(connector_state->crtc); |
| 822 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 823 | if (mstc->port) { |
| 824 | struct nv50_mstm *mstm = mstc->mstm; |
| 825 | return &mstm->msto[head->base.index]->encoder; |
| 826 | } |
| 827 | return NULL; |
| 828 | } |
| 829 | |
| 830 | static struct drm_encoder * |
| 831 | nv50_mstc_best_encoder(struct drm_connector *connector) |
| 832 | { |
| 833 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 834 | if (mstc->port) { |
| 835 | struct nv50_mstm *mstm = mstc->mstm; |
| 836 | return &mstm->msto[0]->encoder; |
| 837 | } |
| 838 | return NULL; |
| 839 | } |
| 840 | |
| 841 | static enum drm_mode_status |
| 842 | nv50_mstc_mode_valid(struct drm_connector *connector, |
| 843 | struct drm_display_mode *mode) |
| 844 | { |
| 845 | return MODE_OK; |
| 846 | } |
| 847 | |
| 848 | static int |
| 849 | nv50_mstc_get_modes(struct drm_connector *connector) |
| 850 | { |
| 851 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 852 | int ret = 0; |
| 853 | |
| 854 | mstc->edid = drm_dp_mst_get_edid(&mstc->connector, mstc->port->mgr, mstc->port); |
| 855 | drm_mode_connector_update_edid_property(&mstc->connector, mstc->edid); |
Jani Nikula | d471ed0 | 2017-11-01 16:21:02 +0200 | [diff] [blame] | 856 | if (mstc->edid) |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 857 | ret = drm_add_edid_modes(&mstc->connector, mstc->edid); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 858 | |
| 859 | if (!mstc->connector.display_info.bpc) |
| 860 | mstc->connector.display_info.bpc = 8; |
| 861 | |
| 862 | if (mstc->native) |
| 863 | drm_mode_destroy(mstc->connector.dev, mstc->native); |
| 864 | mstc->native = nouveau_conn_native_mode(&mstc->connector); |
| 865 | return ret; |
| 866 | } |
| 867 | |
| 868 | static const struct drm_connector_helper_funcs |
| 869 | nv50_mstc_help = { |
| 870 | .get_modes = nv50_mstc_get_modes, |
| 871 | .mode_valid = nv50_mstc_mode_valid, |
| 872 | .best_encoder = nv50_mstc_best_encoder, |
| 873 | .atomic_best_encoder = nv50_mstc_atomic_best_encoder, |
| 874 | }; |
| 875 | |
| 876 | static enum drm_connector_status |
| 877 | nv50_mstc_detect(struct drm_connector *connector, bool force) |
| 878 | { |
| 879 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 880 | if (!mstc->port) |
| 881 | return connector_status_disconnected; |
| 882 | return drm_dp_mst_detect_port(connector, mstc->port->mgr, mstc->port); |
| 883 | } |
| 884 | |
| 885 | static void |
| 886 | nv50_mstc_destroy(struct drm_connector *connector) |
| 887 | { |
| 888 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 889 | drm_connector_cleanup(&mstc->connector); |
| 890 | kfree(mstc); |
| 891 | } |
| 892 | |
| 893 | static const struct drm_connector_funcs |
| 894 | nv50_mstc = { |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 895 | .reset = nouveau_conn_reset, |
| 896 | .detect = nv50_mstc_detect, |
| 897 | .fill_modes = drm_helper_probe_single_connector_modes, |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 898 | .destroy = nv50_mstc_destroy, |
| 899 | .atomic_duplicate_state = nouveau_conn_atomic_duplicate_state, |
| 900 | .atomic_destroy_state = nouveau_conn_atomic_destroy_state, |
| 901 | .atomic_set_property = nouveau_conn_atomic_set_property, |
| 902 | .atomic_get_property = nouveau_conn_atomic_get_property, |
| 903 | }; |
| 904 | |
| 905 | static int |
| 906 | nv50_mstc_new(struct nv50_mstm *mstm, struct drm_dp_mst_port *port, |
| 907 | const char *path, struct nv50_mstc **pmstc) |
| 908 | { |
| 909 | struct drm_device *dev = mstm->outp->base.base.dev; |
| 910 | struct nv50_mstc *mstc; |
| 911 | int ret, i; |
| 912 | |
| 913 | if (!(mstc = *pmstc = kzalloc(sizeof(*mstc), GFP_KERNEL))) |
| 914 | return -ENOMEM; |
| 915 | mstc->mstm = mstm; |
| 916 | mstc->port = port; |
| 917 | |
| 918 | ret = drm_connector_init(dev, &mstc->connector, &nv50_mstc, |
| 919 | DRM_MODE_CONNECTOR_DisplayPort); |
| 920 | if (ret) { |
| 921 | kfree(*pmstc); |
| 922 | *pmstc = NULL; |
| 923 | return ret; |
| 924 | } |
| 925 | |
| 926 | drm_connector_helper_add(&mstc->connector, &nv50_mstc_help); |
| 927 | |
| 928 | mstc->connector.funcs->reset(&mstc->connector); |
| 929 | nouveau_conn_attach_properties(&mstc->connector); |
| 930 | |
Colin Ian King | 27a451e | 2017-08-17 23:03:23 +0100 | [diff] [blame] | 931 | for (i = 0; i < ARRAY_SIZE(mstm->msto) && mstm->msto[i]; i++) |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 932 | drm_mode_connector_attach_encoder(&mstc->connector, &mstm->msto[i]->encoder); |
| 933 | |
| 934 | drm_object_attach_property(&mstc->connector.base, dev->mode_config.path_property, 0); |
| 935 | drm_object_attach_property(&mstc->connector.base, dev->mode_config.tile_property, 0); |
| 936 | drm_mode_connector_set_path_property(&mstc->connector, path); |
| 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | static void |
| 941 | nv50_mstm_cleanup(struct nv50_mstm *mstm) |
| 942 | { |
| 943 | struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev); |
| 944 | struct drm_encoder *encoder; |
| 945 | int ret; |
| 946 | |
| 947 | NV_ATOMIC(drm, "%s: mstm cleanup\n", mstm->outp->base.base.name); |
| 948 | ret = drm_dp_check_act_status(&mstm->mgr); |
| 949 | |
| 950 | ret = drm_dp_update_payload_part2(&mstm->mgr); |
| 951 | |
| 952 | drm_for_each_encoder(encoder, mstm->outp->base.base.dev) { |
| 953 | if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) { |
| 954 | struct nv50_msto *msto = nv50_msto(encoder); |
| 955 | struct nv50_mstc *mstc = msto->mstc; |
| 956 | if (mstc && mstc->mstm == mstm) |
| 957 | nv50_msto_cleanup(msto); |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | mstm->modified = false; |
| 962 | } |
| 963 | |
| 964 | static void |
| 965 | nv50_mstm_prepare(struct nv50_mstm *mstm) |
| 966 | { |
| 967 | struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev); |
| 968 | struct drm_encoder *encoder; |
| 969 | int ret; |
| 970 | |
| 971 | NV_ATOMIC(drm, "%s: mstm prepare\n", mstm->outp->base.base.name); |
| 972 | ret = drm_dp_update_payload_part1(&mstm->mgr); |
| 973 | |
| 974 | drm_for_each_encoder(encoder, mstm->outp->base.base.dev) { |
| 975 | if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) { |
| 976 | struct nv50_msto *msto = nv50_msto(encoder); |
| 977 | struct nv50_mstc *mstc = msto->mstc; |
| 978 | if (mstc && mstc->mstm == mstm) |
| 979 | nv50_msto_prepare(msto); |
| 980 | } |
| 981 | } |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 982 | |
| 983 | if (mstm->disabled) { |
| 984 | if (!mstm->links) |
| 985 | nv50_outp_release(mstm->outp); |
| 986 | mstm->disabled = false; |
| 987 | } |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | static void |
| 991 | nv50_mstm_hotplug(struct drm_dp_mst_topology_mgr *mgr) |
| 992 | { |
| 993 | struct nv50_mstm *mstm = nv50_mstm(mgr); |
| 994 | drm_kms_helper_hotplug_event(mstm->outp->base.base.dev); |
| 995 | } |
| 996 | |
| 997 | static void |
| 998 | nv50_mstm_destroy_connector(struct drm_dp_mst_topology_mgr *mgr, |
| 999 | struct drm_connector *connector) |
| 1000 | { |
| 1001 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
| 1002 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 1003 | |
| 1004 | drm_connector_unregister(&mstc->connector); |
| 1005 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1006 | drm_fb_helper_remove_one_connector(&drm->fbcon->helper, &mstc->connector); |
Lyude Paul | 352672d | 2018-05-02 19:38:48 -0400 | [diff] [blame] | 1007 | |
| 1008 | drm_modeset_lock(&drm->dev->mode_config.connection_mutex, NULL); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1009 | mstc->port = NULL; |
Lyude Paul | 352672d | 2018-05-02 19:38:48 -0400 | [diff] [blame] | 1010 | drm_modeset_unlock(&drm->dev->mode_config.connection_mutex); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1011 | |
| 1012 | drm_connector_unreference(&mstc->connector); |
| 1013 | } |
| 1014 | |
| 1015 | static void |
| 1016 | nv50_mstm_register_connector(struct drm_connector *connector) |
| 1017 | { |
| 1018 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
| 1019 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1020 | drm_fb_helper_add_one_connector(&drm->fbcon->helper, connector); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1021 | |
| 1022 | drm_connector_register(connector); |
| 1023 | } |
| 1024 | |
| 1025 | static struct drm_connector * |
| 1026 | nv50_mstm_add_connector(struct drm_dp_mst_topology_mgr *mgr, |
| 1027 | struct drm_dp_mst_port *port, const char *path) |
| 1028 | { |
| 1029 | struct nv50_mstm *mstm = nv50_mstm(mgr); |
| 1030 | struct nv50_mstc *mstc; |
| 1031 | int ret; |
| 1032 | |
| 1033 | ret = nv50_mstc_new(mstm, port, path, &mstc); |
| 1034 | if (ret) { |
| 1035 | if (mstc) |
| 1036 | mstc->connector.funcs->destroy(&mstc->connector); |
| 1037 | return NULL; |
| 1038 | } |
| 1039 | |
| 1040 | return &mstc->connector; |
| 1041 | } |
| 1042 | |
| 1043 | static const struct drm_dp_mst_topology_cbs |
| 1044 | nv50_mstm = { |
| 1045 | .add_connector = nv50_mstm_add_connector, |
| 1046 | .register_connector = nv50_mstm_register_connector, |
| 1047 | .destroy_connector = nv50_mstm_destroy_connector, |
| 1048 | .hotplug = nv50_mstm_hotplug, |
| 1049 | }; |
| 1050 | |
| 1051 | void |
| 1052 | nv50_mstm_service(struct nv50_mstm *mstm) |
| 1053 | { |
Ben Skeggs | 227f66d | 2017-10-03 16:24:28 +1000 | [diff] [blame] | 1054 | struct drm_dp_aux *aux = mstm ? mstm->mgr.aux : NULL; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1055 | bool handled = true; |
| 1056 | int ret; |
| 1057 | u8 esi[8] = {}; |
| 1058 | |
Ben Skeggs | 227f66d | 2017-10-03 16:24:28 +1000 | [diff] [blame] | 1059 | if (!aux) |
| 1060 | return; |
| 1061 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1062 | while (handled) { |
| 1063 | ret = drm_dp_dpcd_read(aux, DP_SINK_COUNT_ESI, esi, 8); |
| 1064 | if (ret != 8) { |
| 1065 | drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, false); |
| 1066 | return; |
| 1067 | } |
| 1068 | |
| 1069 | drm_dp_mst_hpd_irq(&mstm->mgr, esi, &handled); |
| 1070 | if (!handled) |
| 1071 | break; |
| 1072 | |
| 1073 | drm_dp_dpcd_write(aux, DP_SINK_COUNT_ESI + 1, &esi[1], 3); |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | void |
| 1078 | nv50_mstm_remove(struct nv50_mstm *mstm) |
| 1079 | { |
| 1080 | if (mstm) |
| 1081 | drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, false); |
| 1082 | } |
| 1083 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1084 | static int |
| 1085 | nv50_mstm_enable(struct nv50_mstm *mstm, u8 dpcd, int state) |
| 1086 | { |
| 1087 | struct nouveau_encoder *outp = mstm->outp; |
| 1088 | struct { |
| 1089 | struct nv50_disp_mthd_v1 base; |
| 1090 | struct nv50_disp_sor_dp_mst_link_v0 mst; |
| 1091 | } args = { |
| 1092 | .base.version = 1, |
| 1093 | .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_LINK, |
| 1094 | .base.hasht = outp->dcb->hasht, |
| 1095 | .base.hashm = outp->dcb->hashm, |
| 1096 | .mst.state = state, |
| 1097 | }; |
| 1098 | struct nouveau_drm *drm = nouveau_drm(outp->base.base.dev); |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1099 | struct nvif_object *disp = &drm->display->disp.object; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1100 | int ret; |
| 1101 | |
| 1102 | if (dpcd >= 0x12) { |
| 1103 | ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CTRL, &dpcd); |
| 1104 | if (ret < 0) |
| 1105 | return ret; |
| 1106 | |
| 1107 | dpcd &= ~DP_MST_EN; |
| 1108 | if (state) |
| 1109 | dpcd |= DP_MST_EN; |
| 1110 | |
| 1111 | ret = drm_dp_dpcd_writeb(mstm->mgr.aux, DP_MSTM_CTRL, dpcd); |
| 1112 | if (ret < 0) |
| 1113 | return ret; |
| 1114 | } |
| 1115 | |
| 1116 | return nvif_mthd(disp, 0, &args, sizeof(args)); |
| 1117 | } |
| 1118 | |
| 1119 | int |
| 1120 | nv50_mstm_detect(struct nv50_mstm *mstm, u8 dpcd[8], int allow) |
| 1121 | { |
| 1122 | int ret, state = 0; |
| 1123 | |
| 1124 | if (!mstm) |
| 1125 | return 0; |
| 1126 | |
Ben Skeggs | 3ca03ca | 2016-11-07 14:51:53 +1000 | [diff] [blame] | 1127 | if (dpcd[0] >= 0x12) { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1128 | ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CAP, &dpcd[1]); |
| 1129 | if (ret < 0) |
| 1130 | return ret; |
| 1131 | |
Ben Skeggs | 3ca03ca | 2016-11-07 14:51:53 +1000 | [diff] [blame] | 1132 | if (!(dpcd[1] & DP_MST_CAP)) |
| 1133 | dpcd[0] = 0x11; |
| 1134 | else |
| 1135 | state = allow; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | ret = nv50_mstm_enable(mstm, dpcd[0], state); |
| 1139 | if (ret) |
| 1140 | return ret; |
| 1141 | |
| 1142 | ret = drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, state); |
| 1143 | if (ret) |
| 1144 | return nv50_mstm_enable(mstm, dpcd[0], 0); |
| 1145 | |
| 1146 | return mstm->mgr.mst_state; |
| 1147 | } |
| 1148 | |
| 1149 | static void |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1150 | nv50_mstm_fini(struct nv50_mstm *mstm) |
| 1151 | { |
| 1152 | if (mstm && mstm->mgr.mst_state) |
| 1153 | drm_dp_mst_topology_mgr_suspend(&mstm->mgr); |
| 1154 | } |
| 1155 | |
| 1156 | static void |
| 1157 | nv50_mstm_init(struct nv50_mstm *mstm) |
| 1158 | { |
| 1159 | if (mstm && mstm->mgr.mst_state) |
| 1160 | drm_dp_mst_topology_mgr_resume(&mstm->mgr); |
| 1161 | } |
| 1162 | |
| 1163 | static void |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1164 | nv50_mstm_del(struct nv50_mstm **pmstm) |
| 1165 | { |
| 1166 | struct nv50_mstm *mstm = *pmstm; |
| 1167 | if (mstm) { |
| 1168 | kfree(*pmstm); |
| 1169 | *pmstm = NULL; |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | static int |
| 1174 | nv50_mstm_new(struct nouveau_encoder *outp, struct drm_dp_aux *aux, int aux_max, |
| 1175 | int conn_base_id, struct nv50_mstm **pmstm) |
| 1176 | { |
| 1177 | const int max_payloads = hweight8(outp->dcb->heads); |
| 1178 | struct drm_device *dev = outp->base.base.dev; |
| 1179 | struct nv50_mstm *mstm; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1180 | int ret, i; |
| 1181 | u8 dpcd; |
| 1182 | |
| 1183 | /* This is a workaround for some monitors not functioning |
| 1184 | * correctly in MST mode on initial module load. I think |
| 1185 | * some bad interaction with the VBIOS may be responsible. |
| 1186 | * |
| 1187 | * A good ol' off and on again seems to work here ;) |
| 1188 | */ |
| 1189 | ret = drm_dp_dpcd_readb(aux, DP_DPCD_REV, &dpcd); |
| 1190 | if (ret >= 0 && dpcd >= 0x12) |
| 1191 | drm_dp_dpcd_writeb(aux, DP_MSTM_CTRL, 0); |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1192 | |
| 1193 | if (!(mstm = *pmstm = kzalloc(sizeof(*mstm), GFP_KERNEL))) |
| 1194 | return -ENOMEM; |
| 1195 | mstm->outp = outp; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1196 | mstm->mgr.cbs = &nv50_mstm; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1197 | |
Dhinakaran Pandiyan | 7b0a89a | 2017-01-24 15:49:29 -0800 | [diff] [blame] | 1198 | ret = drm_dp_mst_topology_mgr_init(&mstm->mgr, dev, aux, aux_max, |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1199 | max_payloads, conn_base_id); |
| 1200 | if (ret) |
| 1201 | return ret; |
| 1202 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1203 | for (i = 0; i < max_payloads; i++) { |
| 1204 | ret = nv50_msto_new(dev, outp->dcb->heads, outp->base.base.name, |
| 1205 | i, &mstm->msto[i]); |
| 1206 | if (ret) |
| 1207 | return ret; |
| 1208 | } |
| 1209 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1210 | return 0; |
| 1211 | } |
| 1212 | |
| 1213 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1214 | * SOR |
| 1215 | *****************************************************************************/ |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1216 | static void |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1217 | nv50_sor_update(struct nouveau_encoder *nv_encoder, u8 head, |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1218 | struct nv50_head_atom *asyh, u8 proto, u8 depth) |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1219 | { |
Ben Skeggs | 9ca6f1e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1220 | struct nv50_disp *disp = nv50_disp(nv_encoder->base.base.dev); |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1221 | struct nv50_core *core = disp->core; |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1222 | |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1223 | if (!asyh) { |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1224 | nv_encoder->ctrl &= ~BIT(head); |
| 1225 | if (!(nv_encoder->ctrl & 0x0000000f)) |
| 1226 | nv_encoder->ctrl = 0; |
| 1227 | } else { |
| 1228 | nv_encoder->ctrl |= proto << 8; |
| 1229 | nv_encoder->ctrl |= BIT(head); |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1230 | asyh->or.depth = depth; |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1231 | } |
| 1232 | |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1233 | core->func->sor->ctrl(core, nv_encoder->or, nv_encoder->ctrl, asyh); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1237 | nv50_sor_disable(struct drm_encoder *encoder) |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1238 | { |
| 1239 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1240 | struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc); |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1241 | |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1242 | nv_encoder->crtc = NULL; |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1243 | |
| 1244 | if (nv_crtc) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1245 | struct nvkm_i2c_aux *aux = nv_encoder->aux; |
| 1246 | u8 pwr; |
| 1247 | |
| 1248 | if (aux) { |
| 1249 | int ret = nvkm_rdaux(aux, DP_SET_POWER, &pwr, 1); |
| 1250 | if (ret == 0) { |
| 1251 | pwr &= ~DP_SET_POWER_MASK; |
| 1252 | pwr |= DP_SET_POWER_D3; |
| 1253 | nvkm_wraux(aux, DP_SET_POWER, &pwr, 1); |
| 1254 | } |
| 1255 | } |
| 1256 | |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1257 | nv_encoder->update(nv_encoder, nv_crtc->index, NULL, 0, 0); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1258 | nv50_audio_disable(encoder, nv_crtc); |
| 1259 | nv50_hdmi_disable(&nv_encoder->base.base, nv_crtc); |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1260 | nv50_outp_release(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1261 | } |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1265 | nv50_sor_enable(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1266 | { |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1267 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1268 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1269 | struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state); |
| 1270 | struct drm_display_mode *mode = &asyh->state.adjusted_mode; |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1271 | struct { |
| 1272 | struct nv50_disp_mthd_v1 base; |
| 1273 | struct nv50_disp_sor_lvds_script_v0 lvds; |
| 1274 | } lvds = { |
| 1275 | .base.version = 1, |
| 1276 | .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT, |
| 1277 | .base.hasht = nv_encoder->dcb->hasht, |
| 1278 | .base.hashm = nv_encoder->dcb->hashm, |
| 1279 | }; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1280 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1281 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1282 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1283 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1284 | struct nvbios *bios = &drm->vbios; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1285 | u8 proto = 0xf; |
| 1286 | u8 depth = 0x0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1287 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1288 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1289 | nv_encoder->crtc = encoder->crtc; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1290 | nv50_outp_acquire(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1291 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1292 | switch (nv_encoder->dcb->type) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1293 | case DCB_OUTPUT_TMDS: |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1294 | if (nv_encoder->link & 1) { |
Hauke Mehrtens | 16ef53a9 | 2015-11-03 21:00:10 -0500 | [diff] [blame] | 1295 | proto = 0x1; |
| 1296 | /* Only enable dual-link if: |
| 1297 | * - Need to (i.e. rate > 165MHz) |
| 1298 | * - DCB says we can |
| 1299 | * - Not an HDMI monitor, since there's no dual-link |
| 1300 | * on HDMI. |
| 1301 | */ |
| 1302 | if (mode->clock >= 165000 && |
| 1303 | nv_encoder->dcb->duallink_possible && |
| 1304 | !drm_detect_hdmi_monitor(nv_connector->edid)) |
| 1305 | proto |= 0x4; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1306 | } else { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1307 | proto = 0x2; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1308 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1309 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1310 | nv50_hdmi_enable(&nv_encoder->base.base, mode); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1311 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1312 | case DCB_OUTPUT_LVDS: |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1313 | proto = 0x0; |
| 1314 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1315 | if (bios->fp_no_ddc) { |
| 1316 | if (bios->fp.dual_link) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1317 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1318 | if (bios->fp.if_is_24bit) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1319 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1320 | } else { |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 1321 | if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1322 | if (((u8 *)nv_connector->edid)[121] == 2) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1323 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1324 | } else |
| 1325 | if (mode->clock >= bios->fp.duallink_transition_clk) { |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1326 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1327 | } |
| 1328 | |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1329 | if (lvds.lvds.script & 0x0100) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1330 | if (bios->fp.strapless_is_24bit & 2) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1331 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1332 | } else { |
| 1333 | if (bios->fp.strapless_is_24bit & 1) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1334 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | if (nv_connector->base.display_info.bpc == 8) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1338 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1339 | } |
Ben Skeggs | 4a230fa | 2012-11-09 11:25:37 +1000 | [diff] [blame] | 1340 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1341 | nvif_mthd(&disp->disp->object, 0, &lvds, sizeof(lvds)); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1342 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1343 | case DCB_OUTPUT_DP: |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1344 | if (nv_connector->base.display_info.bpc == 6) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1345 | depth = 0x2; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1346 | else |
| 1347 | if (nv_connector->base.display_info.bpc == 8) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1348 | depth = 0x5; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1349 | else |
Ben Skeggs | bf2c886 | 2012-11-21 14:49:54 +1000 | [diff] [blame] | 1350 | depth = 0x6; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1351 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1352 | if (nv_encoder->link & 1) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1353 | proto = 0x8; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1354 | else |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1355 | proto = 0x9; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1356 | |
| 1357 | nv50_audio_enable(encoder, mode); |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1358 | break; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1359 | default: |
Ben Skeggs | af7db03 | 2016-03-03 12:56:33 +1000 | [diff] [blame] | 1360 | BUG(); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1361 | break; |
| 1362 | } |
Ben Skeggs | ff8ff50 | 2011-07-08 11:53:37 +1000 | [diff] [blame] | 1363 | |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1364 | nv_encoder->update(nv_encoder, nv_crtc->index, asyh, proto, depth); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1365 | } |
| 1366 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1367 | static const struct drm_encoder_helper_funcs |
| 1368 | nv50_sor_help = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1369 | .atomic_check = nv50_outp_atomic_check, |
| 1370 | .enable = nv50_sor_enable, |
| 1371 | .disable = nv50_sor_disable, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1372 | }; |
| 1373 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1374 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1375 | nv50_sor_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1376 | { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1377 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1378 | nv50_mstm_del(&nv_encoder->dp.mstm); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1379 | drm_encoder_cleanup(encoder); |
| 1380 | kfree(encoder); |
| 1381 | } |
| 1382 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1383 | static const struct drm_encoder_funcs |
| 1384 | nv50_sor_func = { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1385 | .destroy = nv50_sor_destroy, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1386 | }; |
| 1387 | |
| 1388 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1389 | nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1390 | { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1391 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1392 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 1393 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1394 | struct nouveau_encoder *nv_encoder; |
| 1395 | struct drm_encoder *encoder; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1396 | int type, ret; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1397 | |
| 1398 | switch (dcbe->type) { |
| 1399 | case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break; |
| 1400 | case DCB_OUTPUT_TMDS: |
| 1401 | case DCB_OUTPUT_DP: |
| 1402 | default: |
| 1403 | type = DRM_MODE_ENCODER_TMDS; |
| 1404 | break; |
| 1405 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1406 | |
| 1407 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 1408 | if (!nv_encoder) |
| 1409 | return -ENOMEM; |
| 1410 | nv_encoder->dcb = dcbe; |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1411 | nv_encoder->update = nv50_sor_update; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1412 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1413 | encoder = to_drm_encoder(nv_encoder); |
| 1414 | encoder->possible_crtcs = dcbe->heads; |
| 1415 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1416 | drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type, |
| 1417 | "sor-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1418 | drm_encoder_helper_add(encoder, &nv50_sor_help); |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1419 | |
| 1420 | drm_mode_connector_attach_encoder(connector, encoder); |
| 1421 | |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1422 | if (dcbe->type == DCB_OUTPUT_DP) { |
Ben Skeggs | 13a8651 | 2017-07-19 16:49:59 +1000 | [diff] [blame] | 1423 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1424 | struct nvkm_i2c_aux *aux = |
| 1425 | nvkm_i2c_aux_find(i2c, dcbe->i2c_index); |
| 1426 | if (aux) { |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1427 | if (disp->disp->object.oclass < GF110_DISP) { |
Ben Skeggs | 13a8651 | 2017-07-19 16:49:59 +1000 | [diff] [blame] | 1428 | /* HW has no support for address-only |
| 1429 | * transactions, so we're required to |
| 1430 | * use custom I2C-over-AUX code. |
| 1431 | */ |
| 1432 | nv_encoder->i2c = &aux->i2c; |
| 1433 | } else { |
| 1434 | nv_encoder->i2c = &nv_connector->aux.ddc; |
| 1435 | } |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1436 | nv_encoder->aux = aux; |
| 1437 | } |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1438 | |
| 1439 | /*TODO: Use DP Info Table to check for support. */ |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1440 | if (disp->disp->object.oclass >= GF110_DISP) { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1441 | ret = nv50_mstm_new(nv_encoder, &nv_connector->aux, 16, |
| 1442 | nv_connector->base.base.id, |
| 1443 | &nv_encoder->dp.mstm); |
| 1444 | if (ret) |
| 1445 | return ret; |
| 1446 | } |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1447 | } else { |
| 1448 | struct nvkm_i2c_bus *bus = |
| 1449 | nvkm_i2c_bus_find(i2c, dcbe->i2c_index); |
| 1450 | if (bus) |
| 1451 | nv_encoder->i2c = &bus->i2c; |
| 1452 | } |
| 1453 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1454 | return 0; |
| 1455 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1456 | |
| 1457 | /****************************************************************************** |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1458 | * PIOR |
| 1459 | *****************************************************************************/ |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1460 | static int |
| 1461 | nv50_pior_atomic_check(struct drm_encoder *encoder, |
| 1462 | struct drm_crtc_state *crtc_state, |
| 1463 | struct drm_connector_state *conn_state) |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1464 | { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1465 | int ret = nv50_outp_atomic_check(encoder, crtc_state, conn_state); |
| 1466 | if (ret) |
| 1467 | return ret; |
| 1468 | crtc_state->adjusted_mode.clock *= 2; |
| 1469 | return 0; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1473 | nv50_pior_disable(struct drm_encoder *encoder) |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1474 | { |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1475 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1476 | struct nv50_core *core = nv50_disp(encoder->dev)->core; |
| 1477 | if (nv_encoder->crtc) |
| 1478 | core->func->pior->ctrl(core, nv_encoder->or, 0x00000000, NULL); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1479 | nv_encoder->crtc = NULL; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1480 | nv50_outp_release(nv_encoder); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1484 | nv50_pior_enable(struct drm_encoder *encoder) |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1485 | { |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1486 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1487 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
| 1488 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1489 | struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state); |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1490 | struct nv50_core *core = nv50_disp(encoder->dev)->core; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1491 | u8 owner = 1 << nv_crtc->index; |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1492 | u8 proto; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1493 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1494 | nv50_outp_acquire(nv_encoder); |
| 1495 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1496 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1497 | switch (nv_connector->base.display_info.bpc) { |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1498 | case 10: asyh->or.depth = 0x6; break; |
| 1499 | case 8: asyh->or.depth = 0x5; break; |
| 1500 | case 6: asyh->or.depth = 0x2; break; |
| 1501 | default: asyh->or.depth = 0x0; break; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | switch (nv_encoder->dcb->type) { |
| 1505 | case DCB_OUTPUT_TMDS: |
| 1506 | case DCB_OUTPUT_DP: |
| 1507 | proto = 0x0; |
| 1508 | break; |
| 1509 | default: |
Ben Skeggs | af7db03 | 2016-03-03 12:56:33 +1000 | [diff] [blame] | 1510 | BUG(); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1511 | break; |
| 1512 | } |
| 1513 | |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1514 | core->func->pior->ctrl(core, nv_encoder->or, (proto << 8) | owner, asyh); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1515 | nv_encoder->crtc = encoder->crtc; |
| 1516 | } |
| 1517 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1518 | static const struct drm_encoder_helper_funcs |
| 1519 | nv50_pior_help = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1520 | .atomic_check = nv50_pior_atomic_check, |
| 1521 | .enable = nv50_pior_enable, |
| 1522 | .disable = nv50_pior_disable, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1523 | }; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1524 | |
| 1525 | static void |
| 1526 | nv50_pior_destroy(struct drm_encoder *encoder) |
| 1527 | { |
| 1528 | drm_encoder_cleanup(encoder); |
| 1529 | kfree(encoder); |
| 1530 | } |
| 1531 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1532 | static const struct drm_encoder_funcs |
| 1533 | nv50_pior_func = { |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1534 | .destroy = nv50_pior_destroy, |
| 1535 | }; |
| 1536 | |
| 1537 | static int |
| 1538 | nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe) |
| 1539 | { |
| 1540 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 1541 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1542 | struct nvkm_i2c_bus *bus = NULL; |
| 1543 | struct nvkm_i2c_aux *aux = NULL; |
| 1544 | struct i2c_adapter *ddc; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1545 | struct nouveau_encoder *nv_encoder; |
| 1546 | struct drm_encoder *encoder; |
| 1547 | int type; |
| 1548 | |
| 1549 | switch (dcbe->type) { |
| 1550 | case DCB_OUTPUT_TMDS: |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1551 | bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev)); |
| 1552 | ddc = bus ? &bus->i2c : NULL; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1553 | type = DRM_MODE_ENCODER_TMDS; |
| 1554 | break; |
| 1555 | case DCB_OUTPUT_DP: |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1556 | aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev)); |
Ben Skeggs | 62b290f | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1557 | ddc = aux ? &aux->i2c : NULL; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1558 | type = DRM_MODE_ENCODER_TMDS; |
| 1559 | break; |
| 1560 | default: |
| 1561 | return -ENODEV; |
| 1562 | } |
| 1563 | |
| 1564 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 1565 | if (!nv_encoder) |
| 1566 | return -ENOMEM; |
| 1567 | nv_encoder->dcb = dcbe; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1568 | nv_encoder->i2c = ddc; |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1569 | nv_encoder->aux = aux; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1570 | |
| 1571 | encoder = to_drm_encoder(nv_encoder); |
| 1572 | encoder->possible_crtcs = dcbe->heads; |
| 1573 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1574 | drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type, |
| 1575 | "pior-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1576 | drm_encoder_helper_add(encoder, &nv50_pior_help); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1577 | |
| 1578 | drm_mode_connector_attach_encoder(connector, encoder); |
| 1579 | return 0; |
| 1580 | } |
| 1581 | |
| 1582 | /****************************************************************************** |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1583 | * Atomic |
| 1584 | *****************************************************************************/ |
| 1585 | |
| 1586 | static void |
| 1587 | nv50_disp_atomic_commit_core(struct nouveau_drm *drm, u32 interlock) |
| 1588 | { |
| 1589 | struct nv50_disp *disp = nv50_disp(drm->dev); |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1590 | struct nv50_core *core = disp->core; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1591 | struct nv50_mstm *mstm; |
| 1592 | struct drm_encoder *encoder; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1593 | |
| 1594 | NV_ATOMIC(drm, "commit core %08x\n", interlock); |
| 1595 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1596 | drm_for_each_encoder(encoder, drm->dev) { |
| 1597 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
| 1598 | mstm = nouveau_encoder(encoder)->dp.mstm; |
| 1599 | if (mstm && mstm->modified) |
| 1600 | nv50_mstm_prepare(mstm); |
| 1601 | } |
| 1602 | } |
| 1603 | |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1604 | core->func->ntfy_init(disp->sync, NV50_DISP_CORE_NTFY); |
| 1605 | core->func->update(core, interlock, true); |
| 1606 | if (core->func->ntfy_wait_done(disp->sync, NV50_DISP_CORE_NTFY, |
| 1607 | disp->core->chan.base.device)) |
| 1608 | NV_ERROR(drm, "core notifier timeout\n"); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1609 | |
| 1610 | drm_for_each_encoder(encoder, drm->dev) { |
| 1611 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
| 1612 | mstm = nouveau_encoder(encoder)->dp.mstm; |
| 1613 | if (mstm && mstm->modified) |
| 1614 | nv50_mstm_cleanup(mstm); |
| 1615 | } |
| 1616 | } |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1617 | } |
| 1618 | |
| 1619 | static void |
| 1620 | nv50_disp_atomic_commit_tail(struct drm_atomic_state *state) |
| 1621 | { |
| 1622 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1623 | struct drm_crtc_state *new_crtc_state, *old_crtc_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1624 | struct drm_crtc *crtc; |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1625 | struct drm_plane_state *new_plane_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1626 | struct drm_plane *plane; |
| 1627 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 1628 | struct nv50_disp *disp = nv50_disp(dev); |
| 1629 | struct nv50_atom *atom = nv50_atom(state); |
| 1630 | struct nv50_outp_atom *outp, *outt; |
| 1631 | u32 interlock_core = 0; |
| 1632 | u32 interlock_chan = 0; |
| 1633 | int i; |
| 1634 | |
| 1635 | NV_ATOMIC(drm, "commit %d %d\n", atom->lock_core, atom->flush_disable); |
| 1636 | drm_atomic_helper_wait_for_fences(dev, state, false); |
| 1637 | drm_atomic_helper_wait_for_dependencies(state); |
| 1638 | drm_atomic_helper_update_legacy_modeset_state(dev, state); |
| 1639 | |
| 1640 | if (atom->lock_core) |
| 1641 | mutex_lock(&disp->mutex); |
| 1642 | |
| 1643 | /* Disable head(s). */ |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1644 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1645 | struct nv50_head_atom *asyh = nv50_head_atom(new_crtc_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1646 | struct nv50_head *head = nv50_head(crtc); |
| 1647 | |
| 1648 | NV_ATOMIC(drm, "%s: clr %04x (set %04x)\n", crtc->name, |
| 1649 | asyh->clr.mask, asyh->set.mask); |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1650 | if (old_crtc_state->active && !new_crtc_state->active) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 1651 | drm_crtc_vblank_off(crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1652 | |
| 1653 | if (asyh->clr.mask) { |
| 1654 | nv50_head_flush_clr(head, asyh, atom->flush_disable); |
| 1655 | interlock_core |= 1; |
| 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | /* Disable plane(s). */ |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1660 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1661 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1662 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 1663 | |
| 1664 | NV_ATOMIC(drm, "%s: clr %02x (set %02x)\n", plane->name, |
| 1665 | asyw->clr.mask, asyw->set.mask); |
| 1666 | if (!asyw->clr.mask) |
| 1667 | continue; |
| 1668 | |
| 1669 | interlock_chan |= nv50_wndw_flush_clr(wndw, interlock_core, |
| 1670 | atom->flush_disable, |
| 1671 | asyw); |
| 1672 | } |
| 1673 | |
| 1674 | /* Disable output path(s). */ |
| 1675 | list_for_each_entry(outp, &atom->outp, head) { |
| 1676 | const struct drm_encoder_helper_funcs *help; |
| 1677 | struct drm_encoder *encoder; |
| 1678 | |
| 1679 | encoder = outp->encoder; |
| 1680 | help = encoder->helper_private; |
| 1681 | |
| 1682 | NV_ATOMIC(drm, "%s: clr %02x (set %02x)\n", encoder->name, |
| 1683 | outp->clr.mask, outp->set.mask); |
| 1684 | |
| 1685 | if (outp->clr.mask) { |
| 1686 | help->disable(encoder); |
| 1687 | interlock_core |= 1; |
| 1688 | if (outp->flush_disable) { |
| 1689 | nv50_disp_atomic_commit_core(drm, interlock_chan); |
| 1690 | interlock_core = 0; |
| 1691 | interlock_chan = 0; |
| 1692 | } |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | /* Flush disable. */ |
| 1697 | if (interlock_core) { |
| 1698 | if (atom->flush_disable) { |
| 1699 | nv50_disp_atomic_commit_core(drm, interlock_chan); |
| 1700 | interlock_core = 0; |
| 1701 | interlock_chan = 0; |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | /* Update output path(s). */ |
| 1706 | list_for_each_entry_safe(outp, outt, &atom->outp, head) { |
| 1707 | const struct drm_encoder_helper_funcs *help; |
| 1708 | struct drm_encoder *encoder; |
| 1709 | |
| 1710 | encoder = outp->encoder; |
| 1711 | help = encoder->helper_private; |
| 1712 | |
| 1713 | NV_ATOMIC(drm, "%s: set %02x (clr %02x)\n", encoder->name, |
| 1714 | outp->set.mask, outp->clr.mask); |
| 1715 | |
| 1716 | if (outp->set.mask) { |
| 1717 | help->enable(encoder); |
| 1718 | interlock_core = 1; |
| 1719 | } |
| 1720 | |
| 1721 | list_del(&outp->head); |
| 1722 | kfree(outp); |
| 1723 | } |
| 1724 | |
| 1725 | /* Update head(s). */ |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1726 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1727 | struct nv50_head_atom *asyh = nv50_head_atom(new_crtc_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1728 | struct nv50_head *head = nv50_head(crtc); |
| 1729 | |
| 1730 | NV_ATOMIC(drm, "%s: set %04x (clr %04x)\n", crtc->name, |
| 1731 | asyh->set.mask, asyh->clr.mask); |
| 1732 | |
| 1733 | if (asyh->set.mask) { |
| 1734 | nv50_head_flush_set(head, asyh); |
| 1735 | interlock_core = 1; |
| 1736 | } |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1737 | |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1738 | if (new_crtc_state->active) { |
| 1739 | if (!old_crtc_state->active) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 1740 | drm_crtc_vblank_on(crtc); |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1741 | if (new_crtc_state->event) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 1742 | drm_crtc_vblank_get(crtc); |
| 1743 | } |
Ben Skeggs | 2b50789 | 2017-01-24 09:32:26 +1000 | [diff] [blame] | 1744 | } |
| 1745 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1746 | /* Update plane(s). */ |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1747 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1748 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1749 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 1750 | |
| 1751 | NV_ATOMIC(drm, "%s: set %02x (clr %02x)\n", plane->name, |
| 1752 | asyw->set.mask, asyw->clr.mask); |
| 1753 | if ( !asyw->set.mask && |
| 1754 | (!asyw->clr.mask || atom->flush_disable)) |
| 1755 | continue; |
| 1756 | |
| 1757 | interlock_chan |= nv50_wndw_flush_set(wndw, interlock_core, asyw); |
| 1758 | } |
| 1759 | |
| 1760 | /* Flush update. */ |
| 1761 | if (interlock_core) { |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1762 | if (interlock_chan || !atom->state.legacy_cursor_update) |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1763 | nv50_disp_atomic_commit_core(drm, interlock_chan); |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1764 | else |
| 1765 | disp->core->func->update(disp->core, 0, false); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | if (atom->lock_core) |
| 1769 | mutex_unlock(&disp->mutex); |
| 1770 | |
| 1771 | /* Wait for HW to signal completion. */ |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1772 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1773 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1774 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 1775 | int ret = nv50_wndw_wait_armed(wndw, asyw); |
| 1776 | if (ret) |
| 1777 | NV_ERROR(drm, "%s: timeout\n", plane->name); |
| 1778 | } |
| 1779 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1780 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 1781 | if (new_crtc_state->event) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1782 | unsigned long flags; |
Mario Kleiner | bd9f660 | 2016-11-23 07:58:54 +0100 | [diff] [blame] | 1783 | /* Get correct count/ts if racing with vblank irq */ |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1784 | if (new_crtc_state->active) |
Dave Airlie | 0c697fa | 2017-08-15 16:16:58 +1000 | [diff] [blame] | 1785 | drm_crtc_accurate_vblank_count(crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1786 | spin_lock_irqsave(&crtc->dev->event_lock, flags); |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1787 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1788 | spin_unlock_irqrestore(&crtc->dev->event_lock, flags); |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1789 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1790 | new_crtc_state->event = NULL; |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1791 | if (new_crtc_state->active) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 1792 | drm_crtc_vblank_put(crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1793 | } |
| 1794 | } |
| 1795 | |
| 1796 | drm_atomic_helper_commit_hw_done(state); |
| 1797 | drm_atomic_helper_cleanup_planes(dev, state); |
| 1798 | drm_atomic_helper_commit_cleanup_done(state); |
| 1799 | drm_atomic_state_put(state); |
| 1800 | } |
| 1801 | |
| 1802 | static void |
| 1803 | nv50_disp_atomic_commit_work(struct work_struct *work) |
| 1804 | { |
| 1805 | struct drm_atomic_state *state = |
| 1806 | container_of(work, typeof(*state), commit_work); |
| 1807 | nv50_disp_atomic_commit_tail(state); |
| 1808 | } |
| 1809 | |
| 1810 | static int |
| 1811 | nv50_disp_atomic_commit(struct drm_device *dev, |
| 1812 | struct drm_atomic_state *state, bool nonblock) |
| 1813 | { |
| 1814 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | d324c5b | 2017-11-01 09:12:25 +1000 | [diff] [blame] | 1815 | struct drm_plane_state *new_plane_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1816 | struct drm_plane *plane; |
| 1817 | struct drm_crtc *crtc; |
| 1818 | bool active = false; |
| 1819 | int ret, i; |
| 1820 | |
| 1821 | ret = pm_runtime_get_sync(dev->dev); |
| 1822 | if (ret < 0 && ret != -EACCES) |
| 1823 | return ret; |
| 1824 | |
| 1825 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 1826 | if (ret) |
| 1827 | goto done; |
| 1828 | |
| 1829 | INIT_WORK(&state->commit_work, nv50_disp_atomic_commit_work); |
| 1830 | |
| 1831 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 1832 | if (ret) |
| 1833 | goto done; |
| 1834 | |
| 1835 | if (!nonblock) { |
| 1836 | ret = drm_atomic_helper_wait_for_fences(dev, state, true); |
| 1837 | if (ret) |
Maarten Lankhorst | 813a7e1 | 2017-07-11 16:33:03 +0200 | [diff] [blame] | 1838 | goto err_cleanup; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1839 | } |
| 1840 | |
Maarten Lankhorst | 8572636 | 2017-07-11 16:33:05 +0200 | [diff] [blame] | 1841 | ret = drm_atomic_helper_swap_state(state, true); |
| 1842 | if (ret) |
| 1843 | goto err_cleanup; |
| 1844 | |
Ben Skeggs | d324c5b | 2017-11-01 09:12:25 +1000 | [diff] [blame] | 1845 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1846 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1847 | struct nv50_wndw *wndw = nv50_wndw(plane); |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1848 | |
Ben Skeggs | ccd27db | 2018-05-08 20:39:47 +1000 | [diff] [blame^] | 1849 | if (asyw->set.image) |
| 1850 | nv50_wndw_ntfy_enable(wndw, asyw); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1851 | } |
| 1852 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1853 | drm_atomic_state_get(state); |
| 1854 | |
| 1855 | if (nonblock) |
| 1856 | queue_work(system_unbound_wq, &state->commit_work); |
| 1857 | else |
| 1858 | nv50_disp_atomic_commit_tail(state); |
| 1859 | |
| 1860 | drm_for_each_crtc(crtc, dev) { |
| 1861 | if (crtc->state->enable) { |
| 1862 | if (!drm->have_disp_power_ref) { |
| 1863 | drm->have_disp_power_ref = true; |
Maarten Lankhorst | 813a7e1 | 2017-07-11 16:33:03 +0200 | [diff] [blame] | 1864 | return 0; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1865 | } |
| 1866 | active = true; |
| 1867 | break; |
| 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | if (!active && drm->have_disp_power_ref) { |
| 1872 | pm_runtime_put_autosuspend(dev->dev); |
| 1873 | drm->have_disp_power_ref = false; |
| 1874 | } |
| 1875 | |
Maarten Lankhorst | 813a7e1 | 2017-07-11 16:33:03 +0200 | [diff] [blame] | 1876 | err_cleanup: |
| 1877 | if (ret) |
| 1878 | drm_atomic_helper_cleanup_planes(dev, state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1879 | done: |
| 1880 | pm_runtime_put_autosuspend(dev->dev); |
| 1881 | return ret; |
| 1882 | } |
| 1883 | |
| 1884 | static struct nv50_outp_atom * |
| 1885 | nv50_disp_outp_atomic_add(struct nv50_atom *atom, struct drm_encoder *encoder) |
| 1886 | { |
| 1887 | struct nv50_outp_atom *outp; |
| 1888 | |
| 1889 | list_for_each_entry(outp, &atom->outp, head) { |
| 1890 | if (outp->encoder == encoder) |
| 1891 | return outp; |
| 1892 | } |
| 1893 | |
| 1894 | outp = kzalloc(sizeof(*outp), GFP_KERNEL); |
| 1895 | if (!outp) |
| 1896 | return ERR_PTR(-ENOMEM); |
| 1897 | |
| 1898 | list_add(&outp->head, &atom->outp); |
| 1899 | outp->encoder = encoder; |
| 1900 | return outp; |
| 1901 | } |
| 1902 | |
| 1903 | static int |
| 1904 | nv50_disp_outp_atomic_check_clr(struct nv50_atom *atom, |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1905 | struct drm_connector_state *old_connector_state) |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1906 | { |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1907 | struct drm_encoder *encoder = old_connector_state->best_encoder; |
| 1908 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1909 | struct drm_crtc *crtc; |
| 1910 | struct nv50_outp_atom *outp; |
| 1911 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1912 | if (!(crtc = old_connector_state->crtc)) |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1913 | return 0; |
| 1914 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1915 | old_crtc_state = drm_atomic_get_old_crtc_state(&atom->state, crtc); |
| 1916 | new_crtc_state = drm_atomic_get_new_crtc_state(&atom->state, crtc); |
| 1917 | if (old_crtc_state->active && drm_atomic_crtc_needs_modeset(new_crtc_state)) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1918 | outp = nv50_disp_outp_atomic_add(atom, encoder); |
| 1919 | if (IS_ERR(outp)) |
| 1920 | return PTR_ERR(outp); |
| 1921 | |
| 1922 | if (outp->encoder->encoder_type == DRM_MODE_ENCODER_DPMST) { |
| 1923 | outp->flush_disable = true; |
| 1924 | atom->flush_disable = true; |
| 1925 | } |
| 1926 | outp->clr.ctrl = true; |
| 1927 | atom->lock_core = true; |
| 1928 | } |
| 1929 | |
| 1930 | return 0; |
| 1931 | } |
| 1932 | |
| 1933 | static int |
| 1934 | nv50_disp_outp_atomic_check_set(struct nv50_atom *atom, |
| 1935 | struct drm_connector_state *connector_state) |
| 1936 | { |
| 1937 | struct drm_encoder *encoder = connector_state->best_encoder; |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1938 | struct drm_crtc_state *new_crtc_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1939 | struct drm_crtc *crtc; |
| 1940 | struct nv50_outp_atom *outp; |
| 1941 | |
| 1942 | if (!(crtc = connector_state->crtc)) |
| 1943 | return 0; |
| 1944 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1945 | new_crtc_state = drm_atomic_get_new_crtc_state(&atom->state, crtc); |
| 1946 | if (new_crtc_state->active && drm_atomic_crtc_needs_modeset(new_crtc_state)) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1947 | outp = nv50_disp_outp_atomic_add(atom, encoder); |
| 1948 | if (IS_ERR(outp)) |
| 1949 | return PTR_ERR(outp); |
| 1950 | |
| 1951 | outp->set.ctrl = true; |
| 1952 | atom->lock_core = true; |
| 1953 | } |
| 1954 | |
| 1955 | return 0; |
| 1956 | } |
| 1957 | |
| 1958 | static int |
| 1959 | nv50_disp_atomic_check(struct drm_device *dev, struct drm_atomic_state *state) |
| 1960 | { |
| 1961 | struct nv50_atom *atom = nv50_atom(state); |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1962 | struct drm_connector_state *old_connector_state, *new_connector_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1963 | struct drm_connector *connector; |
| 1964 | int ret, i; |
| 1965 | |
| 1966 | ret = drm_atomic_helper_check(dev, state); |
| 1967 | if (ret) |
| 1968 | return ret; |
| 1969 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1970 | for_each_oldnew_connector_in_state(state, connector, old_connector_state, new_connector_state, i) { |
| 1971 | ret = nv50_disp_outp_atomic_check_clr(atom, old_connector_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1972 | if (ret) |
| 1973 | return ret; |
| 1974 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1975 | ret = nv50_disp_outp_atomic_check_set(atom, new_connector_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1976 | if (ret) |
| 1977 | return ret; |
| 1978 | } |
| 1979 | |
| 1980 | return 0; |
| 1981 | } |
| 1982 | |
| 1983 | static void |
| 1984 | nv50_disp_atomic_state_clear(struct drm_atomic_state *state) |
| 1985 | { |
| 1986 | struct nv50_atom *atom = nv50_atom(state); |
| 1987 | struct nv50_outp_atom *outp, *outt; |
| 1988 | |
| 1989 | list_for_each_entry_safe(outp, outt, &atom->outp, head) { |
| 1990 | list_del(&outp->head); |
| 1991 | kfree(outp); |
| 1992 | } |
| 1993 | |
| 1994 | drm_atomic_state_default_clear(state); |
| 1995 | } |
| 1996 | |
| 1997 | static void |
| 1998 | nv50_disp_atomic_state_free(struct drm_atomic_state *state) |
| 1999 | { |
| 2000 | struct nv50_atom *atom = nv50_atom(state); |
| 2001 | drm_atomic_state_default_release(&atom->state); |
| 2002 | kfree(atom); |
| 2003 | } |
| 2004 | |
| 2005 | static struct drm_atomic_state * |
| 2006 | nv50_disp_atomic_state_alloc(struct drm_device *dev) |
| 2007 | { |
| 2008 | struct nv50_atom *atom; |
| 2009 | if (!(atom = kzalloc(sizeof(*atom), GFP_KERNEL)) || |
| 2010 | drm_atomic_state_init(dev, &atom->state) < 0) { |
| 2011 | kfree(atom); |
| 2012 | return NULL; |
| 2013 | } |
| 2014 | INIT_LIST_HEAD(&atom->outp); |
| 2015 | return &atom->state; |
| 2016 | } |
| 2017 | |
| 2018 | static const struct drm_mode_config_funcs |
| 2019 | nv50_disp_func = { |
| 2020 | .fb_create = nouveau_user_framebuffer_create, |
Noralf Trønnes | d0f54f5 | 2017-12-05 19:25:00 +0100 | [diff] [blame] | 2021 | .output_poll_changed = drm_fb_helper_output_poll_changed, |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2022 | .atomic_check = nv50_disp_atomic_check, |
| 2023 | .atomic_commit = nv50_disp_atomic_commit, |
| 2024 | .atomic_state_alloc = nv50_disp_atomic_state_alloc, |
| 2025 | .atomic_state_clear = nv50_disp_atomic_state_clear, |
| 2026 | .atomic_state_free = nv50_disp_atomic_state_free, |
| 2027 | }; |
| 2028 | |
| 2029 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2030 | * Init |
| 2031 | *****************************************************************************/ |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2032 | |
Ben Skeggs | 2a44e49 | 2011-11-09 11:36:33 +1000 | [diff] [blame] | 2033 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2034 | nv50_display_fini(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2035 | { |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2036 | struct nouveau_encoder *nv_encoder; |
| 2037 | struct drm_encoder *encoder; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2038 | struct drm_plane *plane; |
| 2039 | |
| 2040 | drm_for_each_plane(plane, dev) { |
| 2041 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 2042 | if (plane->funcs != &nv50_wndw) |
| 2043 | continue; |
| 2044 | nv50_wndw_fini(wndw); |
| 2045 | } |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2046 | |
| 2047 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 2048 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
| 2049 | nv_encoder = nouveau_encoder(encoder); |
| 2050 | nv50_mstm_fini(nv_encoder->dp.mstm); |
| 2051 | } |
| 2052 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2053 | } |
| 2054 | |
| 2055 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2056 | nv50_display_init(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2057 | { |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 2058 | struct nv50_core *core = nv50_disp(dev)->core; |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2059 | struct drm_encoder *encoder; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2060 | struct drm_plane *plane; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 2061 | |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 2062 | core->func->init(core); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2063 | |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2064 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 2065 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
Ben Skeggs | 9c5753b | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 2066 | struct nouveau_encoder *nv_encoder = |
| 2067 | nouveau_encoder(encoder); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2068 | nv50_mstm_init(nv_encoder->dp.mstm); |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2069 | } |
| 2070 | } |
| 2071 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2072 | drm_for_each_plane(plane, dev) { |
| 2073 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 2074 | if (plane->funcs != &nv50_wndw) |
| 2075 | continue; |
| 2076 | nv50_wndw_init(wndw); |
| 2077 | } |
| 2078 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 2079 | return 0; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2083 | nv50_display_destroy(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2084 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2085 | struct nv50_disp *disp = nv50_disp(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2086 | |
Ben Skeggs | 9ca6f1e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 2087 | nv50_core_del(&disp->core); |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 2088 | |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 2089 | nouveau_bo_unmap(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2090 | if (disp->sync) |
| 2091 | nouveau_bo_unpin(disp->sync); |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 2092 | nouveau_bo_ref(NULL, &disp->sync); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 2093 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2094 | nouveau_display(dev)->priv = NULL; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2095 | kfree(disp); |
| 2096 | } |
| 2097 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2098 | MODULE_PARM_DESC(atomic, "Expose atomic ioctl (default: disabled)"); |
| 2099 | static int nouveau_atomic = 0; |
| 2100 | module_param_named(atomic, nouveau_atomic, int, 0400); |
| 2101 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2102 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2103 | nv50_display_create(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2104 | { |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 2105 | struct nvif_device *device = &nouveau_drm(dev)->client.device; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2106 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2107 | struct dcb_table *dcb = &drm->vbios.dcb; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2108 | struct drm_connector *connector, *tmp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2109 | struct nv50_disp *disp; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 2110 | struct dcb_output *dcbe; |
Ben Skeggs | 7c5f6a8 | 2012-03-04 16:25:59 +1000 | [diff] [blame] | 2111 | int crtcs, ret, i; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2112 | |
| 2113 | disp = kzalloc(sizeof(*disp), GFP_KERNEL); |
| 2114 | if (!disp) |
| 2115 | return -ENOMEM; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2116 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2117 | mutex_init(&disp->mutex); |
| 2118 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2119 | nouveau_display(dev)->priv = disp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2120 | nouveau_display(dev)->dtor = nv50_display_destroy; |
| 2121 | nouveau_display(dev)->init = nv50_display_init; |
| 2122 | nouveau_display(dev)->fini = nv50_display_fini; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 2123 | disp->disp = &nouveau_display(dev)->disp; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2124 | dev->mode_config.funcs = &nv50_disp_func; |
Ilia Mirkin | c20bb15 | 2018-02-03 14:11:23 -0500 | [diff] [blame] | 2125 | dev->driver->driver_features |= DRIVER_PREFER_XBGR_30BPP; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2126 | if (nouveau_atomic) |
| 2127 | dev->driver->driver_features |= DRIVER_ATOMIC; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2128 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2129 | /* small shared memory area we use for notifiers and semaphores */ |
Ben Skeggs | bab7cc1 | 2016-05-24 17:26:48 +1000 | [diff] [blame] | 2130 | ret = nouveau_bo_new(&drm->client, 4096, 0x1000, TTM_PL_FLAG_VRAM, |
Maarten Lankhorst | bb6178b | 2014-01-09 11:03:15 +0100 | [diff] [blame] | 2131 | 0, 0x0000, NULL, NULL, &disp->sync); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2132 | if (!ret) { |
Ben Skeggs | 547ad07 | 2014-11-10 12:35:06 +1000 | [diff] [blame] | 2133 | ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2134 | if (!ret) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2135 | ret = nouveau_bo_map(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2136 | if (ret) |
| 2137 | nouveau_bo_unpin(disp->sync); |
| 2138 | } |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2139 | if (ret) |
| 2140 | nouveau_bo_ref(NULL, &disp->sync); |
| 2141 | } |
| 2142 | |
| 2143 | if (ret) |
| 2144 | goto out; |
| 2145 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2146 | /* allocate master evo channel */ |
Ben Skeggs | 9ca6f1e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 2147 | ret = nv50_core_new(drm, &disp->core); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2148 | if (ret) |
| 2149 | goto out; |
| 2150 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2151 | /* create crtc objects to represent the hw heads */ |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 2152 | if (disp->disp->object.oclass >= GF110_DISP) |
Ilia Mirkin | eba5e56 | 2017-07-03 13:06:26 -0400 | [diff] [blame] | 2153 | crtcs = nvif_rd32(&device->object, 0x612004) & 0xf; |
Ben Skeggs | 63718a0 | 2012-11-16 11:44:14 +1000 | [diff] [blame] | 2154 | else |
Ilia Mirkin | eba5e56 | 2017-07-03 13:06:26 -0400 | [diff] [blame] | 2155 | crtcs = 0x3; |
Ben Skeggs | 63718a0 | 2012-11-16 11:44:14 +1000 | [diff] [blame] | 2156 | |
Ilia Mirkin | eba5e56 | 2017-07-03 13:06:26 -0400 | [diff] [blame] | 2157 | for (i = 0; i < fls(crtcs); i++) { |
| 2158 | if (!(crtcs & (1 << i))) |
| 2159 | continue; |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2160 | ret = nv50_head_create(dev, i); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2161 | if (ret) |
| 2162 | goto out; |
| 2163 | } |
| 2164 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2165 | /* create encoder/connector objects based on VBIOS DCB table */ |
| 2166 | for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) { |
| 2167 | connector = nouveau_connector_create(dev, dcbe->connector); |
| 2168 | if (IS_ERR(connector)) |
| 2169 | continue; |
| 2170 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 2171 | if (dcbe->location == DCB_LOC_ON_CHIP) { |
| 2172 | switch (dcbe->type) { |
| 2173 | case DCB_OUTPUT_TMDS: |
| 2174 | case DCB_OUTPUT_LVDS: |
| 2175 | case DCB_OUTPUT_DP: |
| 2176 | ret = nv50_sor_create(connector, dcbe); |
| 2177 | break; |
| 2178 | case DCB_OUTPUT_ANALOG: |
| 2179 | ret = nv50_dac_create(connector, dcbe); |
| 2180 | break; |
| 2181 | default: |
| 2182 | ret = -ENODEV; |
| 2183 | break; |
| 2184 | } |
| 2185 | } else { |
| 2186 | ret = nv50_pior_create(connector, dcbe); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2187 | } |
| 2188 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 2189 | if (ret) { |
| 2190 | NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n", |
| 2191 | dcbe->location, dcbe->type, |
| 2192 | ffs(dcbe->or) - 1, ret); |
Ben Skeggs | 94f54f5 | 2013-03-05 22:26:06 +1000 | [diff] [blame] | 2193 | ret = 0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | /* cull any connectors we created that don't have an encoder */ |
| 2198 | list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) { |
| 2199 | if (connector->encoder_ids[0]) |
| 2200 | continue; |
| 2201 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2202 | NV_WARN(drm, "%s has no encoders, removing\n", |
Jani Nikula | 8c6c361 | 2014-06-03 14:56:18 +0300 | [diff] [blame] | 2203 | connector->name); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2204 | connector->funcs->destroy(connector); |
| 2205 | } |
| 2206 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2207 | out: |
| 2208 | if (ret) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2209 | nv50_display_destroy(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2210 | return ret; |
| 2211 | } |