1 /* $NetBSD: nouveau_dp.c,v 1.4 2021/12/18 23:45:32 riastradh Exp $ */ 2 3 /* 4 * Copyright 2009 Red Hat Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 * OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: Ben Skeggs 25 */ 26 27 #include <sys/cdefs.h> 28 __KERNEL_RCSID(0, "$NetBSD: nouveau_dp.c,v 1.4 2021/12/18 23:45:32 riastradh Exp $"); 29 30 #include <drm/drm_dp_helper.h> 31 32 #include "nouveau_drv.h" 33 #include "nouveau_connector.h" 34 #include "nouveau_encoder.h" 35 #include "nouveau_crtc.h" 36 37 #include <nvif/class.h> 38 #include <nvif/cl5070.h> 39 40 MODULE_PARM_DESC(mst, "Enable DisplayPort multi-stream (default: enabled)"); 41 static int nouveau_mst = 1; 42 module_param_named(mst, nouveau_mst, int, 0400); 43 44 static void 45 nouveau_dp_probe_oui(struct drm_device *dev, struct nvkm_i2c_aux *aux, u8 *dpcd) 46 { 47 struct nouveau_drm *drm = nouveau_drm(dev); 48 u8 buf[3]; 49 50 if (!(dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT)) 51 return; 52 53 if (!nvkm_rdaux(aux, DP_SINK_OUI, buf, 3)) 54 NV_DEBUG(drm, "Sink OUI: %02"PRIx8"%02"PRIx8"%02"PRIx8"\n", 55 buf[0], buf[1], buf[2]); 56 57 if (!nvkm_rdaux(aux, DP_BRANCH_OUI, buf, 3)) 58 NV_DEBUG(drm, "Branch OUI: %02"PRIx8"%02"PRIx8"%02"PRIx8"\n", 59 buf[0], buf[1], buf[2]); 60 61 } 62 63 int 64 nouveau_dp_detect(struct nouveau_encoder *nv_encoder) 65 { 66 struct drm_device *dev = nv_encoder->base.base.dev; 67 struct nouveau_drm *drm = nouveau_drm(dev); 68 struct nvkm_i2c_aux *aux; 69 u8 dpcd[8]; 70 int ret; 71 72 aux = nv_encoder->aux; 73 if (!aux) 74 return -ENODEV; 75 76 ret = nvkm_rdaux(aux, DP_DPCD_REV, dpcd, sizeof(dpcd)); 77 if (ret) 78 return ret; 79 80 nv_encoder->dp.link_bw = 27000 * dpcd[1]; 81 nv_encoder->dp.link_nr = dpcd[2] & DP_MAX_LANE_COUNT_MASK; 82 83 NV_DEBUG(drm, "display: %dx%d dpcd 0x%02x\n", 84 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw, dpcd[0]); 85 NV_DEBUG(drm, "encoder: %dx%d\n", 86 nv_encoder->dcb->dpconf.link_nr, 87 nv_encoder->dcb->dpconf.link_bw); 88 89 if (nv_encoder->dcb->dpconf.link_nr < nv_encoder->dp.link_nr) 90 nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr; 91 if (nv_encoder->dcb->dpconf.link_bw < nv_encoder->dp.link_bw) 92 nv_encoder->dp.link_bw = nv_encoder->dcb->dpconf.link_bw; 93 94 NV_DEBUG(drm, "maximum: %dx%d\n", 95 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw); 96 97 nouveau_dp_probe_oui(dev, aux, dpcd); 98 99 ret = nv50_mstm_detect(nv_encoder->dp.mstm, dpcd, nouveau_mst); 100 if (ret == 1) 101 return NOUVEAU_DP_MST; 102 if (ret == 0) 103 return NOUVEAU_DP_SST; 104 return ret; 105 } 106