Home | History | Annotate | Line # | Download | only in nouveau
nouveau_dp.c revision 1.2.18.1
      1 /*	$NetBSD: nouveau_dp.c,v 1.2.18.1 2019/06/10 22:08:06 christos 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.2.18.1 2019/06/10 22:08:06 christos Exp $");
     29 
     30 #include <drm/drmP.h>
     31 #include <drm/drm_dp_helper.h>
     32 
     33 #include "nouveau_drm.h"
     34 #include "nouveau_connector.h"
     35 #include "nouveau_encoder.h"
     36 #include "nouveau_crtc.h"
     37 
     38 static void
     39 nouveau_dp_probe_oui(struct drm_device *dev, struct nvkm_i2c_aux *aux, u8 *dpcd)
     40 {
     41 	struct nouveau_drm *drm = nouveau_drm(dev);
     42 	u8 buf[3];
     43 
     44 	if (!(dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
     45 		return;
     46 
     47 	if (!nvkm_rdaux(aux, DP_SINK_OUI, buf, 3))
     48 		NV_DEBUG(drm, "Sink OUI: %02"PRIx8"%02"PRIx8"%02"PRIx8"\n",
     49 			     buf[0], buf[1], buf[2]);
     50 
     51 	if (!nvkm_rdaux(aux, DP_BRANCH_OUI, buf, 3))
     52 		NV_DEBUG(drm, "Branch OUI: %02"PRIx8"%02"PRIx8"%02"PRIx8"\n",
     53 			     buf[0], buf[1], buf[2]);
     54 
     55 }
     56 
     57 int
     58 nouveau_dp_detect(struct nouveau_encoder *nv_encoder)
     59 {
     60 	struct drm_device *dev = nv_encoder->base.base.dev;
     61 	struct nouveau_drm *drm = nouveau_drm(dev);
     62 	struct nvkm_i2c_aux *aux;
     63 	u8 *dpcd = nv_encoder->dp.dpcd;
     64 	int ret;
     65 
     66 	aux = nv_encoder->aux;
     67 	if (!aux)
     68 		return -ENODEV;
     69 
     70 	ret = nvkm_rdaux(aux, DP_DPCD_REV, dpcd, 8);
     71 	if (ret)
     72 		return ret;
     73 
     74 	nv_encoder->dp.link_bw = 27000 * dpcd[1];
     75 	nv_encoder->dp.link_nr = dpcd[2] & DP_MAX_LANE_COUNT_MASK;
     76 
     77 	NV_DEBUG(drm, "display: %dx%d dpcd 0x%02x\n",
     78 		     nv_encoder->dp.link_nr, nv_encoder->dp.link_bw, dpcd[0]);
     79 	NV_DEBUG(drm, "encoder: %dx%d\n",
     80 		     nv_encoder->dcb->dpconf.link_nr,
     81 		     nv_encoder->dcb->dpconf.link_bw);
     82 
     83 	if (nv_encoder->dcb->dpconf.link_nr < nv_encoder->dp.link_nr)
     84 		nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr;
     85 	if (nv_encoder->dcb->dpconf.link_bw < nv_encoder->dp.link_bw)
     86 		nv_encoder->dp.link_bw = nv_encoder->dcb->dpconf.link_bw;
     87 
     88 	NV_DEBUG(drm, "maximum: %dx%d\n",
     89 		     nv_encoder->dp.link_nr, nv_encoder->dp.link_bw);
     90 
     91 	nouveau_dp_probe_oui(dev, aux, dpcd);
     92 	return 0;
     93 }
     94