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