Home | History | Annotate | Line # | Download | only in nouveau
nouveau_dp.c revision 1.2
      1 /*	$NetBSD: nouveau_dp.c,v 1.2 2016/01/29 22:25:45 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.2 2016/01/29 22:25:45 riastradh 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 #include <core/class.h>
     39 
     40 #include <subdev/gpio.h>
     41 #include <subdev/i2c.h>
     42 
     43 static void
     44 nouveau_dp_probe_oui(struct drm_device *dev, struct nouveau_i2c_port *auxch,
     45 		     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 (!nv_rdaux(auxch, 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 (!nv_rdaux(auxch, 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 bool
     64 nouveau_dp_detect(struct drm_encoder *encoder)
     65 {
     66 	struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
     67 	struct drm_device *dev = encoder->dev;
     68 	struct nouveau_drm *drm = nouveau_drm(dev);
     69 	struct nouveau_i2c_port *auxch;
     70 	u8 *dpcd = nv_encoder->dp.dpcd;
     71 	int ret;
     72 
     73 	auxch = nv_encoder->i2c;
     74 	if (!auxch)
     75 		return false;
     76 
     77 	ret = nv_rdaux(auxch, DP_DPCD_REV, dpcd, 8);
     78 	if (ret)
     79 		return false;
     80 
     81 	nv_encoder->dp.link_bw = 27000 * dpcd[1];
     82 	nv_encoder->dp.link_nr = dpcd[2] & DP_MAX_LANE_COUNT_MASK;
     83 
     84 	NV_DEBUG(drm, "display: %dx%d dpcd 0x%02x\n",
     85 		     nv_encoder->dp.link_nr, nv_encoder->dp.link_bw, dpcd[0]);
     86 	NV_DEBUG(drm, "encoder: %dx%d\n",
     87 		     nv_encoder->dcb->dpconf.link_nr,
     88 		     nv_encoder->dcb->dpconf.link_bw);
     89 
     90 	if (nv_encoder->dcb->dpconf.link_nr < nv_encoder->dp.link_nr)
     91 		nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr;
     92 	if (nv_encoder->dcb->dpconf.link_bw < nv_encoder->dp.link_bw)
     93 		nv_encoder->dp.link_bw = nv_encoder->dcb->dpconf.link_bw;
     94 
     95 	NV_DEBUG(drm, "maximum: %dx%d\n",
     96 		     nv_encoder->dp.link_nr, nv_encoder->dp.link_bw);
     97 
     98 	nouveau_dp_probe_oui(dev, auxch, dpcd);
     99 
    100 	return true;
    101 }
    102